Mac包管理器Homebrew的安裝方法
世上無難事,只要找到 Homebrew 的正確安裝方式。
Homebrew 是什么
Homebrew是 mac的包管理器,僅需執(zhí)行相應(yīng)的命令,就能下載安裝需要的軟件包,可以省掉自己去下載、解壓、拖拽(安裝)等繁瑣的步驟。 比如安裝服務(wù)器 nginx,打開終端執(zhí)行以下命令即可安裝:
brew install nginx
Homebrew 官方文檔https://brew.sh/
Homebrew 怎么安裝
方法一:brew官網(wǎng)的安裝腳本
執(zhí)行命令:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
這時很可能會出現(xiàn)一個問題: 要么下載極其龜速,要么直接出現(xiàn)如下提示
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
原因:這是http://raw.githubusercontent.com訪問不穩(wěn)定引起的。
此時需要換一種科學(xué)高效的安裝方法,即方法二。
方法二:brew 鏡像安裝腳本(親測最快速最有效)
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
該腳本用了中科大鏡像加速訪問,僅修改倉庫地址部分,不會產(chǎn)生安全隱患。 關(guān)于中科大所提供的 Homebrew 鏡像服務(wù)https://lug.ustc.edu.cn/wiki/mirrors/help/brew.git
注:注意這里的速度,幾百kib/s或幾m/s才是正常的。若只有幾kib/s,通常為無效的安裝方法,一般加載了百分之幾十后就會報錯。
Homebrew 安裝時如何避坑
1.若出現(xiàn) Error: Checksum mismatch.
報錯代碼如下:
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: Checksum mismatch.
Expected: b065e5e3783954f3e65d8d3a6377ca51649bfcfa21b356b0dd70490f74c6bd86
Actual: e8a348fe5d5c2b966bab84052062f0317944122dea5fdfdc84ac6d0bd513c137
Archive: /Users/joyce/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
To retry an incomplete download, remove the file above.
Error: Failed to install Homebrew Portable Ruby (and your system version is too old)!
Failed during: /usr/local/bin/brew update --force
這里是由Homebrew目錄下的portable-ruby-2.6.3_2.yosemite.bottle.tar.gz文件引起的安裝中斷,只需要到上面對應(yīng)的路徑里,刪掉這個文件,重新執(zhí)行安裝命令即可:
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
2.若卡在了Cloning into...
由這里的龜速可斷定卡住了,立馬用Control + C中斷腳本,然后執(zhí)行以下命令:
cd "$(brew --repo)/Library/Taps/" mkdir homebrew && cd homebrew git clone git://mirrors.ustc.edu.cn/homebrew-core.git
執(zhí)行后可看到:
速度立馬快得飛起,一下子就能裝好。
注:最后出現(xiàn) Installation successful! 或者 Checking out files: 100% (5392/5392), done. 說明安裝成功。
Homebrew安裝完為何需要配置
前面已經(jīng)提到,Homebrew通常用來下載軟件的,但它在安裝軟件時非常慢。為了提升安裝速度,需要更改 Homebrew 的安裝源,將其替換成國內(nèi)鏡像。
這里用的是由中科大負(fù)責(zé)托管維護(hù)的 Homebrew 鏡像。其中,前兩個為必須配置的項(xiàng)目,后兩個可按需配置。
1.必備設(shè)置替換 brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
替換 homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
2.按需設(shè)置替換 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
替換homebrew-bottles:
首先要先區(qū)分你的mac用哪種終端工具,如果是 bash,則執(zhí)行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile source ~/.bash_profile
若是 zsh,則執(zhí)行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc source ~/.zshrc
注:Homebrew 主要由四個部分組成: brew、homebrew-core 、homebrew-cask、homebrew-bottles,它們對應(yīng)的功能如下:
組成 | 功能 |
---|---|
Homebrew | 源代碼倉庫 |
homebrew-core | Homebrew 核心源 |
homebrew-cask | 提供macos應(yīng)用和大型二進(jìn)制文件的安裝 |
homebrew-bottles | 預(yù)編譯二進(jìn)制軟件包 |
Homebrew 基本用法有哪些
// 查詢: brew search 軟件名 // 安裝: brew install 軟件名 // 卸載: brew uninstall 軟件名 // 更新 Homebrew: brew update // 查看 Homebrew 配置信息: brew config <br data-filtered="filtered"><br data-filtered="filtered">// 查看 Homebrew 安裝軟件的具體路徑: brew list 軟件名
#例如: brew list ant /usr/local/Cellar/ant/1.10.9/bin/ant /usr/local/Cellar/ant/1.10.9/bin/antRun /usr/local/Cellar/ant/1.10.9/bin/antRun.pl /usr/local/Cellar/ant/1.10.9/bin/complete-ant-cmd.pl /usr/local/Cellar/ant/1.10.9/bin/runant.pl /usr/local/Cellar/ant/1.10.9/bin/runant.py /usr/local/Cellar/ant/1.10.9/libexec/bin/ (6 files) /usr/local/Cellar/ant/1.10.9/libexec/etc/ (16 files) /usr/local/Cellar/ant/1.10.9/libexec/lib/ (55 files) /usr/local/Cellar/ant/1.10.9/libexec/manual/ (1572 files) /usr/local/Cellar/ant/1.10.9/libexec/ (8 files) #說明: #1、通過brew install安裝應(yīng)用最先是放在/usr/local/Cellar/目錄下。 #2、有些應(yīng)用會自動創(chuàng)建軟鏈接放在/usr/bin或者/usr/sbin,同時也會將整個文件夾放在/usr/local #3、可以使用 brew list 軟件名 (比如 brew list ant)確定安裝位置
注:使用官方腳本同樣會遇到uninstall地址無法訪問問題,可以替換為下面腳本:
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/uninstall)"
寫在最后
在此之前試過了好幾種安裝方法,比如下載一個 brew_install.rb的文件,然后執(zhí)行命令ruby brew_install.rb,一開始行得通,但下載到中途就會報錯,而且出錯的方法不一,也嘗試過好幾種相應(yīng)的解決方法,最終都夭折了,只有這個鏡像安裝才能成功,而且下載速度非常快。
到此這篇關(guān)于Mac安裝Homebrew的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
網(wǎng)絡(luò)基礎(chǔ)-數(shù)據(jù)包
本文主要講解數(shù)據(jù)包在網(wǎng)絡(luò)中的生命履歷來引出一些網(wǎng)絡(luò)基礎(chǔ)知識,介紹的比較詳細(xì),需要了解的小伙伴可以自己參考一下2021-08-08基于 Dubbo Admin 動態(tài)調(diào)整服務(wù)超時時間的操作步驟
Dubbo提供動態(tài)調(diào)整超時時間的服務(wù)治理能力,可以在無需重啟應(yīng)用的情況下,動態(tài)調(diào)整服務(wù)超時時間,這篇文章主要介紹了基于 Dubbo Admin 動態(tài)調(diào)整服務(wù)超時時間,需要的朋友可以參考下2022-12-12