Mac使用HomeBrew


前言

考慮許久終於決定入手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
 
        


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM