Mac安装homebrew
(1)获取homebrew文件到本地
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh >> brew_install
打开brew_install文件,vi brew_install
在文件中搜索BREW_REPO,/BREW_REPO
把BREW_REPO的值 https://github.com/Homebrew/brew 替换成 https://mirrors.ustc.edu.cn/brew.git
(2)运行brew_install文件
./brew_install
(3)这时很可能会卡在Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'这个位置
进入/usr/local/Homebrew/Library/路径下,删除Taps文件夹
rm -rf Taps/
输入如下命令:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
(4)再次运行brew_install
./brew_install
(5)更换国内镜像
# 步骤一
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 步骤二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
长期替换
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
brew常用命令
- 安装软件: brew install git
- 卸载软件: brew uninstall git
- 搜索软件: brew search git
- 显示已经安装软件列表: brew list
- 删除旧版本安装包缓存: brew cleanup git、brew cleanup
- 查看那些已安装的程序需要更新: brew outdated
- 更新软件,把所有的Formula目录更新: brew update
- 更新某具体软件: brew upgrade git
- 锁定某个软件禁止更新: brew pin git
- 解除禁更锁定: brew unpin git
- 查看brew存放安装包的缓存地址: brew --cache
- 显示安装的服务: brew services list
- 启动: brew services start mysql
- 停止: brew services stop mysql
- 重启: brew services restart mysql