1,官方给的安装homebrew的方法
此方法适合有科学上网的用户
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
这个方法在国内是非常慢的,这就需要修改下载地址,接方法2
2,采用中科院的源安装homebrew
步骤一: 获取install文件:在当前用户下打开终端,将以下命令粘贴到终端 + 回车
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
上面的地址被强,请到这里手动拷贝https://blog.csdn.net/SunJavaApplet/article/details/105218762
在终端输入命令
open ~/brew_install
步骤二:更改文件中的链接资源,将原有的链接资源替换成清华大学的镜像资源
打开文件后修改源,如下
把这句用#注释掉
BREW_REPO = “https://github.com/Homebrew/brew“.freeze
修改为这句
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze
步骤三:安装homebrew,运行修改了的brew_install
/usr/bin/ruby ~/brew_install
当卡住时,按ctrl+c退出。出现卡住是因为homebrew-core源不通,核心代码无法下载到本地,采用如下方法变通解决,接方法3.
3,可以修改文件夹权限的用户
解决了chown: /usr/local: Operation not permitted报错的问题
sudo chown -R $(whoami) /usr/local/*
安装brew:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git//usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
安装brew cask:
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git//usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask --depth=1
4,修改权限失效用户
一层一层新建如下文件夹
/usr/local/Homebrew/Library/Taps/homebrew
在终端输入命令进入到homebrew文件夹
cd "$(brew --repo)/Library/Taps/homebrew"
首先确定安装了git,再执行下面代码
安装brew:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
安装brew cask:
git clone git://mirrors.ustc.edu.cn/homebrew-cask.git
5,替换成国内源:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替换Bottle源:
bash用户(shell用户):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
zsh用户:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
执行更新brew命令:
brew update
接着执行brew检测命令:
brew doctor
到此应该就安装上homebrew了,参考链接:https://zhuanlan.zhihu.com/p/59805070