首页 > 技术文章 > Mac使用HomeBrew

chnmig 2019-09-03 14:34 原文

前言

考虑许久终于决定入手mac耍耍,还是因为要找工作了,手上的win本大学入的,现在使用卡顿太多,另外就是mac作为程序员之友仰慕已久.决定在PDD入了.到手后发现mac真的跟win有很大差别.还是要慢慢适应啊,这里记录mac上的软件包管理 HomeBrew 的使用.

变更记录

# 19.9.3 起笔

正文

官网

https://brew.sh/index_zh-cn

安装Brew

在终端执行

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

第一次执行会要求你输入mac的密码

下载速度过慢尝试FQ或修改源(推荐FQ)

等待运行完成即可

升级Git

mac自带git但是有可能出现版本低的情况

因为我们已经安装了Brew所以最好将软件包都交给 Brew 维护

在终端输入

brew install git

等待安装完成即可

安装Python

同理, mac虽然自带了python但是版本是2.7

我们可以安装一个python3

brew install python

会安装最近的python版本

请注意,此时输入python3才可进入brew安装的版本

输入python是系统的python2

Brew常用命令

https://docs.brew.sh/

下方都以软件包 git 为例

brew help  # 查看帮助
brew install git  # 安装包,如是软件需要使用 brew cask install
brew uninstall git  # 卸载包
brew search git  # 搜索包
brew list  # 查看安装的所有包
brew update  # 更新brew,同时会将包列下(有更新的包后面会有✅)
brew outdated  # 查看可更新的包
brew upgrade git  # 更新包(不加包名代表更新全部)
brew info git  # 查看包信息(安装时间/位置/大小等)
brew home git  # 访问包官网
brew cleanup git  # 清理本地的所有老版本包(不加包名代表清理全部)

Brew切换国内源

切换源到中科大,再也不担心网络问题啦

# 替换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:
# 中科大:
 echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
 source ~/.bash_profile

# 应用生效:
 brew update

或者是清华源

# 替换brew.git:
 cd "$(brew --repo)"
# 清华大学:
 git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

# 替换homebrew-core.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

# 替换homebrew-bottles:
# 清华大学:
 echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
 source ~/.bash_profile

# 应用生效:
 brew update

Brew重置源

将源更改为默认源

# 重置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-bottles:
vim ~/.bash_profile
去除 export HOMEBREW_BOTTLE_DOMAIN 行
保存后刷新:
source ~/.bash_profile

# 应用生效:
 brew update

推荐阅读