首先,各大Linux官方一般都有自己的包管理器,一般首選官方的包管理器。
安裝一些依賴:sudo apt install ruby build-essential
官方的給出的一鍵安裝命令:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
此時很可能出現錯誤:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
如果官方安裝太慢或者出現這個錯誤按照下文的操作!
官方的安裝太慢,我們可以更改安裝源爲國內的源(我更改的是國內的清華源)。接下來將一步步講解。
-
下載安裝檢查腳本:
-
如果有wget,可以嘗試使用wget下載:
wget https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh -O install.sh
如果出現錯誤:
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.228.133 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443... failed: Connection refused.
請使用下面的方法!
-
直接使用瀏覽器打開鏈接
https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh
,看到的內容全部複製下來,創建一個文件命名爲install.sh
,把複製的內容全部粘貼再這裏面。
-
-
更改安裝檢查腳本:
在安裝檢查腳本里面有一行:
exec ruby -e "`curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install`" "$@"
我們需要更改爲:
exec ruby "install_linux.rb" "$@"
-
下載安裝文件:
-
如果有wget,可以嘗試使用wget下載:
wget https://raw.githubusercontent.com/Linuxbrew/install/master/install -O install_linux.rb
如果出現錯誤:
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.228.133 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443... failed: Connection refused.
請使用下面的方法!
-
直接使用瀏覽器打開鏈接
https://raw.githubusercontent.com/Linuxbrew/install/master/install
,看到的內容全部複製下來,創建一個文件命名爲install_linux.rb
,把複製的內容全部粘貼再這裏面。
-
-
更改安裝文件:
修改官方文件裏面的源:
在
BREW_REPO = "https://github.com/Homebrew/brew".freeze
前加#
號 在下方加入一行:
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
接下來給安裝檢查文件加上執行權限:chmod +x install.sh
,然後執行./install.sh
等待安裝,不出意外就會看見:
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Tapping homebrew/core
Cloning into '/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core'...
下載倉庫的地址在國外,下載會比較慢,我們可以手動下載。
首先使用組合鍵CTRL+C
關閉安裝過程,
創建目錄:
mkdir /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew
,
進入目錄:
cd /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew
。
然後執行:
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
回到原來目錄:cd -
再次執行:./install.sh
執行後會提示:
- Configure Homebrew in your ~/.profile by running
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >>~/.profile
- Add Homebrew to your PATH
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
- We recommend that you install GCC by running:
brew install gcc
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.
如果出現了這個Warning
則需要手動進行一些操作:
如果是bash用戶:
- 編輯
.profile
或者.bash_profile
,添加一行:eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
如果是zsh用戶:
- 編輯
.zhcrc
,添加一行eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
重啓一下或者直接在命令行執行:eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
,就可以正常使用brew。
使用過程中更換爲國內的源使用起來更加舒適
更換brew的源爲清華源:
git -C /home/linuxbrew/.linuxbrew/Homebrew remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask-drivers remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
brew update
更改bintray鏡像:
臨時更改:export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
長期更改:
-
bash用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.profile
-
zsh用戶
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc