mac下國內安裝Homebrew教程

2021-10-09 19:24:44 字數 3169 閱讀 6634

homebrew是一款包管理工具,目前支援macos和linux系統。主要有四個部分組成: brew、homebrew-core 、homebrew-cask、homebrew-bottles。

名稱 說明

brew homebrew 源**倉庫

homebrew-core homebrew 核心源

homebrew-cask 提供 macos 應用和大型二進位制檔案的安裝

homebrew-bottles 預編譯二進位制軟體包

本文主要介紹homebrew安裝方式以及如何加速訪問,順便普及一些必要的知識。

指令碼說明

homebrew預設安裝指令碼:

curl: (7) failed to connect to raw.githubusercontent.com port 443: operation timed out

請使用下面的指令碼:

/usr/bin/ruby -e 「(cu

rl−f

sslh

ttps

://c

dn.j

sdel

ivr.

net/

gh/i

neo6

/hom

ebre

w−in

stal

l/in

stal

l)"2.

執行命令

/usr

/bin

/rub

y−e"

(curl -fssl " 2. 執行命令 /usr/bin/ruby -e "

2.執行

命令/u

sr/b

in/r

uby−

e"(curl -fssl 」

如果命令執行中卡在下面資訊:

cd 「$(brew --repo)/library/taps/」

mkdir homebrew && cd homebrew

git clone git:

成功執行之後繼續執行前文的安裝命令。

最後看到==> installation successful!就說明安裝成功了。

最最後執行:

brew update

cd 「$(brew --repo)/library/taps/」

cd homebrew

git clone

/usr/bin/ruby -e 「$(curl -fssl

設定映象

brew、homebrew/core是必備專案,homebrew/cask、homebrew/bottles按需設定。

通過 brew config命令檢視配置資訊。

4.1 中科大源

注意bottles可以臨時設定,在終端執行下面命令:

export homebrew_bottle_domain=

4.2 清華大學源

git -c 「$(brew --repo)」 remote set-url origin

git -c 「$(brew --repo homebrew/core)」 remote set-url origin

git -c 「$(brew --repo homebrew/cask)」 remote set-url origin

brew update

echo 『export homebrew_bottle_domain= >> ~/.bash_profile

source ~/.bash_profile

4.3 恢復

git -c 「$(brew --repo)」 remote set-url origin

git -c 「$(brew --repo homebrew/core)」 remote set-url origin

git -c 「$(brew --repo homebrew/cask)」 remote set-url origin

brew update

homebrew-bottles配置只能手動刪除,將 ~/.bash_profile檔案中的 homebrew_bottle_domain=內容刪除,並執行 source ~/.bash_profile。

其他5.1 cask

目前cask是從github上讀取軟體源,而github api對匿名訪問有限制,如果使用比較頻繁的話,可以申請api token,然後在環境變數中配置到homebrew_github_api_token。

在.bash_profile中追加:

export homebrew_github_api_token=yourtoken

總結在前面的過程中我們把brew和homebrew-core的位址都指向到中科大映象。

原理是通過修改install指令碼,在裡面預設映象位址來做到的。

#!/usr/bin/ruby

homebrew_prefix = 「/usr/local」.freeze

homebrew_repository = 「/usr/local/homebrew」.freeze

homebrew_cache = 「#/library/caches/homebrew」.freeze

brew_repo = 「」.freeze

最後不完美的地方是我們只能預設brew映象,沒找到比較好的辦法預設homebrew-core、homebrew-cask的git位址。

Mac下使用國內映象安裝Homebrew

根據官網上的方法,在終端輸入 usr bin ruby e curl fssl 依文中所述,進行安裝。由於官方棄用了舊的homebrew倉庫,將homebrew程式與軟體包拆分成了兩個倉庫。與文中描述不符,也未能成功安裝。於是稍作修改,記錄於此。新增brew.git與homebrew core.gi...

Mac下使用國內映象安裝Homebrew

根據官網上的方法,在終端輸入 usr bin ruby e curl fssl 依文中所述,進行安裝。由於官方棄用了舊的homebrew倉庫,將homebrew程式與軟體包拆分成了兩個倉庫。與文中描述不符,也未能成功安裝。於是稍作修改,記錄於此。新增brew.git與homebrew core.gi...

國內環境下mac安裝homebrew的正確方式

配置好梯子之後 在終端中依次執行下面命令的前兩個或者只執行最後乙個,下面的1087要換成你梯子對應的埠號 1.配置http訪問的 2.配置https訪問的 3.配置http和https訪問的 export all proxy socks5 這個方法簡單直接,而且影響面小,只對當前終端有效 方法2安全...