Homebrew安装、使用以及切换国内下载镜像

最近换了macbook pro,所以开始折腾mac os上的开发环境,记在这里方便自己和别人

Homebrew是什么

官网:http://mxcl.github.com/homebrew/
Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X. 官方的解释非常明了,Homebrew是一个包管理器,用于在Mac上安装一些OS X没有的UNIX工具(比如著名的wget)。
换个说法,homebrew就像ubuntu的ape-get,同样的就像linux的yum,都是包管理器。
Homebrew将这些工具统统安装到了 /usr/local/Cellar 目录中,并在 /usr/local/bin 中创建符号链接。
Homebrew依赖github,安装如下:

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

使用Homebrew

搜索软件:brew search 软件名,例:brew search tomcat
安装软件:brew install 软件名,例:brew install tomcat@7
卸载软件:brew uninstall 软件名,例:brew uninstall tomcat@7

使用search后,homebrew会列出所有相关的可供安装的软件,比如我运行 brew search tomcat, 等待一会会列出tomcat的多个版本,直接install tomcat@7 ,安装的是7_79版本

其他命令

brew list   —列出已安装的软件
brew update   —更新Homebrew
brew home  *—用浏览器打开
brew info   *—显示软件内容信息
brew deps * — 显示包依赖
brew server *  —启动web服务器,可以通过浏览器访问http://localhost:4567/ 来同网页来管理包
brew -h brew   —帮助

更快的使用Homebrew

生活在天朝的程序员都能体会到,很多www不能访问,所以只能准备梯子,homebrew的大部分软件源都是在github上或国外网站的,所以只要你能翻墙也能下载,但是我们也可以做个好孩子(^ ^),把homebrew的镜像源换成国内的。
切换镜像需要注意,分别替换brew的core源,Bottles源
从网上看了很多帖子,我都总结了,所以看这里就够了:

  • coding.net的镜像
  • 中科大的镜像
  • 清华大学的镜像

CODING.NET(命令不对,待查)

另外2个是教育网,我们这些走出学校的码农连着还是慢,不如这个saas平台,做代码托管以及项目管理的saas产品

$ cd /usr/local && git remote set-url origin https://git.coding.net/homebrew/homebrew.git

$ cd $home && brew update

中科大

# 替换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

# 直接执行一下命令,会写入 ~/.bash_profile,如果想恢复,直接在.bash_profile注掉就可以了
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

#如果想恢复,注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源。 重启bash或让bash重读配置文件。

清华大学(亲测,可用)

# 重置brew.git:
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 重置homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git

删除Homebrew

cd `brew –prefix`
rm -rf Cellar
brew prune 
rm `git ls-files` 
rm -rf Library .git .gitignore bin/brew
rm  -rf [README.md](http://readme.md/) share/man/man1/brew
rm -rf Library/Homebrew Library/Aliases 
rm -rf Library/Formula Library/Contributions
rm -rf ~/Library/Caches/Homebrew
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值