Mac下如何安装Homebrew?

Mac下该如何安装Homebrew包管理软件呢?

喜欢这个问题 | 分享 | 新建回答

回答

冯纪忠雄

Mar 3, 2019
1 赞

Homebrew是Mac OS缺失的软件包的管理工具。安装Homebrew非常简单,只要把如下一行命令复制到mac的终端命令行中回车运行即可安装成功,安装可能会需要一段时间。(当然,电脑必须联网,才能安装的)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"



Homebrew安装好后,比如想要安装某软件包时,只要“brew install 软件包的名称”即可,以安装wget软件包为例:

$ brew install wget



Homebrew会将下载的软件包安装到独立目录,并将其文件自动软链接到 /usr/local;比如上述例子中下好的wget软件:

$ cd /usr/local
$ find Cellar
Cellar/wget/1.16.1
Cellar/wget/1.16.1/bin/wget
Cellar/wget/1.16.1/share/man/man1/wget.1

$ ls -l bin
bin/wget -> ../Cellar/wget/1.16.1/bin/wget




喷火的尾巴

Jan 3, 2024
1 赞

另外一个帖子关于如何安装HomeBrew已经说的很好了,我补充一下如何替换brew的源为国内的清华的Homebrew镜像。否则用海外的HomeBrew太慢了。

首先查看当前Homebrew源:

cd "$(brew --repo)"  
git remote -v

可能会显示是Github的Homebrew源;Github国内不稳定,换成清华镜像。

git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/homebrew.git

再次运行“git remote -v”就会显示已经换成清华的Homebrew源了。

“不对~~  上述替换HomeBrew源为清华的源”的方法已经过时了!请重新按照下面方法操作。

直接修改系统环境变量的配置文件

sudo vim ~/.zshrc

加入如下内容:

export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"

然后重新打开终端即可。