前话
各路神仙如果在看到这个文章的时候,已经折腾好久homebrew的安装了,那么,根据我这篇经验分享,如果能顺利安装成功的话,可能会出现一个error: Not a valid ref: refs/remotes/origin/master ,这是因为多次下载,导致一些冲突,最简单粗暴的解决就是卸载重装。
创建并打开一个文件:vim uninstall.rb
复制下面的ruby代码:
#!/usr/bin/ruby
STDERR.print Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" EOS Kernel.exec "/bin/bash", "-c", '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"' + ' uninstall ' + ARGV.join(" ") |
然后 :wq 保存
然后执行 ruby uninstall.rb
这个问题参考自这篇博客(谢谢作者):https://www.cnblogs.com/lfri/p/14310513.html
安装原生 Homebrew
第一步:首先创建安装目录
sudo mkdir -p /opt/homebrew
第二步:将目录属主修改为当前用户,方便以后用当前用户直接brew install软件
sudo chown -R $(whoami) /opt/homebrew
第三步:进入 /opt 文件夹
cd /opt
第四步:直接下载homebrew tar包并解压
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
第五步:将路径增加到PATH环境变量中
如果使用的是zsh则直接修改~/.zshrc,如果使用的是bash,则修改~/.bash_profile
path=('/opt/homebrew/bin' $path)
export PATH
第六步:新开一个Terminal窗口或者在当前窗口让环境变量生效
source ~/.zshrc
完成:
现在可以安装软件了,注意要使用-s选项,表示编译源码安装
brew install -s wget
参考1:https://www.dbform.com/2020/11/30/how-to-install-native-homebrew-on-an-apple-silicon-m1-mac/
参考2:https://sspai.com/post/63935
在安装HomeBrew(或者安装成功 执行相关指令)时遇到错误提示:
Error: Failure while executing: git clone https://github.com/Homebrew/homebrew-core /usr/local/Library/Taps/homebrew/homebrew-core --config core.autocrlf=false --depth=1 -q
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core -q
解决方案:
在终端中依次执行sudo chown -R apple:staff *和brew doctor两个命令如下图:
localhost:~ sant$ sudo chown -R apple:staff *
localhost:~ sant$ brew doctor
待指令执行结束,homebrew 也就修复好了。
有小伙伴反应在执行
sudo chown -R apple:staff
命令时 会提示 chown: apple: illegal user name
出现这个提示的原因是找不到apple 这个用户
解决方案也很简单:
在终端中执行 whoami 命令,查询当前用户的名称,
将 sudo chown -R apple:staff 中的apple 替换成查询出的用户名,运行该命令;
例如我的设备查出来的名称为 sant
在终端中执行
sudo chown -R sant(你设备的当前用户名称):staff
待指令运行结束,继续后面的操作。
附 homebrew常用操作:
brew install xxx 安装xxx
brew uninstall xxx 卸载xxx
brew update xxx 更新xxx
brew doctor 修复brew
这个安装方案参考自这篇博客(谢谢作者):找不出来了,折腾了好久,反正这个也有很多摘抄,总之谢谢原创的分享吧。
在参考这篇博客之前,试了很多种安装方式:
比如这个篇高大上的教程:https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
没成功。