macOS系统下安装Homebrew

macOS系统下安装Homebrew

系统版本信息:macOS Mojave 10.14.3

接下来进入正题,最近为了折腾Vue的环境在网上找了不少的资料,包括博客,提问啥的,发现到最后都解决不了问题,一直报错,直到翻到了这个Mac下使用国内镜像安装HomebrewHomeBrew 官方安装太慢而失败?这么搞就行.(转载),受此启发并结合自己的安装经历,给那篇补充一些细节,并希望给后来者一些帮助和启发。

这里我们使用国内镜像安装。在此感谢前面的两位dalao

1.获取install文件并编辑

cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install
编辑的话直接在Finder里面搜索brew_install,双击之后打开,一般会用Xcode打开。原文说的“注释掉BREW_REPO = "https://github.com/Homebrew/brew".freeze和CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze”,不知为何,我这儿没有CORE_TAP_REPO这一行,不过没关系,新增上去就行了。

修改后代码和截图如下

#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere (which is
# unsupported) you can untar https://github.com/Homebrew/brew/tarball/master
# anywhere you like.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CORE_TAP = "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
#BREW_REPO = "https://github.com/Homebrew/brew".freeze#修改前
BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git".freeze#修改后
CORE_TAP_REPO = "git://mirrors.ustc.edu.cn/homebrew-core.git".freeze#新增

macOS系统下安装Homebrew

2.开始安装

/usr/bin/ruby ~/brew_install
在这里我没有遇到原文下面提问的朋友遇到的卡住报错不动等问题,仅停顿了一会儿。

3.替换源

#替换homebrew默认源
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

#替换homebrew-core源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

4.brew更新

brew update

最后:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

相关推荐