Mac OSX 下安装homebrew并更新国内镜像源

homebrew能干什么

使用 Homebrew 安装 mac osx(或您的 Linux 系统)没有预装但你需要的软件;类似于ubuntu的apt-get、centos的yum。

官网:https://brew.sh/

官方说明:
Homebrew 会将软件包安装到独立目录,并将其文件软链接至 /usr/local
Homebrew 不会将文件安装到它本身目录之外,所以您可将 Homebrew 安装到任意位置。
完全基于 Git 和 Ruby,所以自由修改的同时你仍可以轻松撤销你的变更或与上游更新合并。

homebrew的安装

输入命令:

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

homebrew的卸载

将install换位uninstall就行了:

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

homebrew的基本命令

1、安装软件包

brew install PackageName

2、卸载软件包

brew uninstall PackageName

3、查询可用安装包

brew search PackageName

4、列出已安装包

brew list

5、更新安装包

brew upgrade

6、更新homebrew

brew update

7、Homebrew常用命令

brew -v								查询Homebrew版本
brew -h								brew帮助
brew update							更新Homebrew
brew install <pkg_name>				安装任意软件
brew uninstall <pkg_name>			卸载任意软件
brew search <pkg_name>				查询任意包
brew list							列出安装列表
brew info <pkg_name>				查看任意包内容信息
brew upgrade <pkg_name>				更新任意包
brew cleanup <pkg_name>				删除具体旧软件
brew cleanup						删除所有旧软件
brew outdated						已安装的包是否需要更新
brew deps							已安装的包是否需要更新

homebrew 更新国内源

1、中科大源

替换brew.git:


cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

替换homebrew-core.git:

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

替换Homebrew Bottles源:

对于bash用户

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

中科大源地址: 官方地址

2、清华源

替换现有上游

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

复原

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update

清华源地址:官方地址

3、阿里云源

替换brew.git:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

替换homebrew-core.git:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

替换homebrew-bottles:

brew update
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

阿里源地址:官方地址

发布了33 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/niyaozuozuihao/article/details/100539863