安裝homebrew
官網方法:macOS(或 Linux)缺失的軟件包的管理器 — Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安裝brew
如果已經安裝會順便卸載就得brew
執行:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
需要輸入密碼授權一下,并且會讓你選擇鏡像源,我選擇的中科大的,1。
原因可以看一下中科大源,官方的介紹:
image.png
腳本輸出如下:
tank@tankerdeMacBook-Pro ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
開始執行Brew自動安裝程序
[cunkai.wang@foxmail.com]
[2020-10-17 14:34:27][10.15]
https://zhuanlan.zhihu.com/p/111014448
請選擇一個下載鏡像,例如中科大,輸入1回車。
源有時候不穩定,如果git克隆報錯重新運行腳本選擇源。cask非必須,有部分人需要。
1、中科大下載源 2、清華大學下載源 3、北京外國語大學下載源 4、騰訊下載源(不顯示下載進度) 5、阿里巴巴下載源(缺少cask源)
請輸入序號: 1
你選擇了中國科學技術大學下載源
!!!此腳本將要刪除之前的brew(包括它下載的軟件),請自行備份。
->是否現在開始執行腳本(N/Y)Y
--> 腳本開始執行
==> 通過命令刪除之前的brew、創建一個新的Homebrew文件夾
(設置開機密碼:在左上角蘋果圖標->系統偏好設置->"用戶與群組"->更改密碼)
(如果提示This incident will be reported. 在"用戶與群組"中查看是否管理員)
請輸入開機密碼,輸入過程不顯示,輸入完后回車
Password:
開始執行
-> 創建文件夾 /usr/local/Homebrew
此步驟成功
-> 創建文件夾 /usr/local/Caskroom
此步驟成功
-> 創建文件夾 /usr/local/Cellar
此步驟成功
-> 創建文件夾 /usr/local/var/homebrew
此步驟成功
-> 創建文件夾 /usr/local/etc
此步驟成功
-> 創建文件夾 /usr/local/include
此步驟成功
-> 創建文件夾 /usr/local/lib
此步驟成功
-> 創建文件夾 /usr/local/sbin
此步驟成功
-> 創建文件夾 /usr/local/opt
此步驟成功
-> 創建文件夾 /usr/local/share/zsh
此步驟成功
-> 創建文件夾 /usr/local/share/zsh/site-functions
此步驟成功
-> 創建文件夾 /usr/local/var/homebrew/linked
此步驟成功
-> 創建文件夾 /usr/local/Frameworks
此步驟成功
git version 2.24.3 (Apple Git-128)
下載速度覺得慢可以ctrl+c或control+c重新運行腳本選擇下載源
==> 克隆Homebrew基本文件(32M+)
未發現Git代理(屬于正常狀態)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 164443, done.
remote: Total 164443 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (164443/164443), 40.59 MiB | 25.69 MiB/s, done.
Resolving deltas: 100% (122247/122247), done.
此步驟成功
==> 創建brew的替身
此步驟成功
==> 克隆Homebrew Core(224M+)
此處如果顯示Password表示需要再次輸入開機密碼,輸入完后回車
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 806736, done.
remote: Total 806736 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (806736/806736), 320.87 MiB | 29.34 MiB/s, done.
Resolving deltas: 100% (542292/542292), done.
此步驟成功
==> 克隆Homebrew Cask(248M+) 類似AppStore
此處如果顯示Password表示需要再次輸入開機密碼,輸入完后回車
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 485786, done.
remote: Total 485786 (delta 0), reused 0 (delta 0)B | 15.37 MiB/s
Receiving objects: 100% (485786/485786), 220.15 MiB | 22.69 MiB/s, done.
Resolving deltas: 100% (345538/345538), done.
此步驟成功
==> 配置國內鏡像源HOMEBREW BOTTLE
此步驟成功
==> 安裝完成,brew版本
10.15
brew -v
Homebrew 2.5.6-65-g1670883-dirty
Homebrew/homebrew-core (git revision 73588; last commit 2020-10-17)
Homebrew/homebrew-cask (git revision 022d57; last commit 2020-10-17)
Brew前期配置成功
==> brew update
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics have been recorded yet (or will be during this `brew` run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
Already up-to-date.
上一句如果提示Already up-to-date表示成功
Brew自動安裝程序運行完成
國內地址已經配置完成
初步介紹幾個brew命令
本地軟件庫列表:brew ls
查找軟件:brew search google(其中google替換為要查找的軟件關鍵字)
查看brew版本:brew -v 更新brew版本:brew update
現在可以輸入命令open ~/.zshrc -e 或者 open ~/.bash_profile -e 整理一下重復的語句(運行 echo $SHELL 可以查看應該打開那一個文件修改)
https://zhuanlan.zhihu.com/p/111014448 歡迎來給點個贊
tank@tankerdeMacBook-Pro ~ % brew -v
Homebrew 2.5.6-65-g1670883-dirty
Homebrew/homebrew-core (git revision 73588; last commit 2020-10-17)
Homebrew/homebrew-cask (git revision 022d57; last commit 2020-10-17)
tank@tankerdeMacBook-Pro ~ % brew ls
tank@tankerdeMacBook-Pro ~ % brew search google
==> Formulae
aws-google-auth google-authenticator-libpam google-benchmark google-go google-java-format google-sparsehash google-sql-tool googler
==> Casks
google-ads-editor google-cloud-sdk google-japanese-ime marshallofsound-google-play-music-player homebrew/cask-versions/google-japanese-ime-dev
google-analytics-opt-out google-drive-file-stream google-photos-backup-and-sync moefe-google-translate
google-backup-and-sync google-earth-pro google-trends homebrew/cask-versions/google-chrome-beta
google-chat google-featured-photos google-web-designer homebrew/cask-versions/google-chrome-canary
google-chrome google-hangouts googleappengine homebrew/cask-versions/google-chrome-dev
tank@tankerdeMacBook-Pro ~ % brew update
Already up-to-date.
安裝完成,驗證一下源:
tank@tankerdeMacBook-Pro homebrew-core % cd "$(brew --repo)"
tank@tankerdeMacBook-Pro Homebrew % git remote -v
origin https://mirrors.ustc.edu.cn/brew.git (fetch)
origin https://mirrors.ustc.edu.cn/brew.git (push)
tank@tankerdeMacBook-Pro Homebrew % cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
tank@tankerdeMacBook-Pro homebrew-core % git remote -v
origin https://mirrors.ustc.edu.cn/homebrew-core.git (fetch)
origin https://mirrors.ustc.edu.cn/homebrew-core.git (push)
tank@tankerdeMacBook-Pro homebrew-core % cd "$(brew --repo)"/Library/Taps/homebrew/homebrew-cask
tank@tankerdeMacBook-Pro homebrew-cask % git remote -v
origin https://mirrors.ustc.edu.cn/homebrew-cask.git (fetch)
origin https://mirrors.ustc.edu.cn/homebrew-cask.git (push)
tank@tankerdeMacBook-Pro homebrew-cask %
Mac 下 brew 切換為國內源
簡介
Homebrew 是一款自由及開放源代碼的軟件包管理系統,用以簡化 macOS 和 linux 系統上的軟件安裝過程。它擁有安裝、卸載、更新、查看、搜索等很多實用的功能,通過簡單的一條指令,就可以實現包管理,十分方便快捷。
Homebrew 主要有四個部分組成: brew、homebrew-core 、homebrew-bottles、homebrew-cask。
image.png
替換為阿里源
# 查看 brew.git 當前源
$ cd "$(brew --repo)" && git remote -v
origin https://github.com/Homebrew/brew.git (fetch)
origin https://github.com/Homebrew/brew.git (push)
# 查看 homebrew-core.git 當前源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin https://github.com/Homebrew/homebrew-core.git (fetch)
origin https://github.com/Homebrew/homebrew-core.git (push)
# 修改 brew.git 為阿里源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 修改 homebrew-core.git 為阿里源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# zsh 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# bash 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 刷新源
$ brew update
替換為清華源
# 替換各個源
$ 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
# zsh 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# bash 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 刷新源
$ brew update
替換為中科大源
# 替換各個源
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# zsh 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
$ source ~/.zshrc
# bash 替換 brew bintray 鏡像
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 刷新源
$ brew update
重置為官方源
# 重置 brew.git 為官方源
$ git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 重置 homebrew-core.git 為官方源
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 重置 homebrew-cask.git 為官方源
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
# zsh 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.zshrc
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# bash 注釋掉 HOMEBREW_BOTTLE_DOMAIN 配置
$ vi ~/.bash_profile
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# 刷新源
$ brew update
單獨配置鏡像源
如下:Homebrew 源使用幫助 — USTC Mirror Help 文檔
需要操作如下幾步
image.png