Mac Brew 安裝及配置,解決多種錯誤問題的方法


Mac Brew 安裝及配置,解決多種錯誤問題的方法

mac 終端下,執行以下命令,即可安裝brew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
由於是國外的源,下載很慢而且不穩定,安裝一次不一定能夠下載成功,如果看到安裝過程有報錯或者提示下載失敗的,需要重復多執行幾次。

需要先看報錯信息,逐步解決下面的問題后才能正常安裝成功。
在終端環境下,brew --version 查看brew的版本,也可以驗證brew是否安裝成功


---------
安裝完畢后,發現使用brew命令,卻還是提示:-bash: brew: command not found
其實解決這個問題真的很簡單。如下:
sudo vim .bash_profile
添加:
export PATH=/usr/local/bin:$PATH
保存,source .bash_profile使配置修改生效。
再次使用brew 命令就ok了。
==============
問題:macOS安裝Homebrew時總是報錯(Failed to connect to raw.githubusercontent.com port 443: Connection refused)
原因:由於某些原因,導致GitHub的raw.githubusercontent.com域名解析被污染了。
解決辦法:通過修改hosts解決此問題。
在https://www.ipaddress.com/查詢raw.githubusercontent.com的真實IP
199.232.68.133 raw.githubusercontent.com
修改hosts
sudo vim /etc/hosts
添加如下內容:
199.232.68.133 raw.githubusercontent.com

==============
fatal: unable to access 'https://github.com/Homebrew/brew/': Proxy CONNECT aborted
試着先在終端 ping github.com
MacBook-Pro:~$ ping github.com
PING github.com (13.250.177.223): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
如果 ping 出來是這種結果,就接着看第二步

查詢github.com對於的IP地址
https://site.ip138.com/github.com/
美國 華盛頓 西雅圖 140.82.114.4
..... 有多個對應的IP地址

修改 hosts 配置
在終端中 sudo vim /etc/hosts 打開編輯文件
添加 140.82.114.4 github.com

然后再ping github.com 如果還是timeout則換一個IP,直到正常ping得通為止
PING github.com (140.82.114.4): 56 data bytes
64 bytes from 140.82.114.4: icmp_seq=0 ttl=51 time=289.722 ms

==================

朋友推薦的brew源極大提升速度
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles/
不用等brew更新 
export HOMEBREW_NO_AUTO_UPDATE=1

==============

mac 安裝brew慢的問題解決

fatal: unable to access 'https://github.com/Homebrew/brew/': transfer closed with outstanding read data remaining

git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1

fatal: destination path '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core' already exists and is not an empty directory.

# 步驟一
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.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

#步驟三
brew update

-------------
還原方法
# 步驟一
cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

# 步驟二
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core

#步驟三
brew update
--------------
診斷homebrew
brew doctor

Warning: Broken symlinks were found. Remove them with `brew cleanup`:

================
Homebrew是一個包管理器,用於在Mac上安裝一些OSX上沒有的UNIX工具(比如wget)。
brew官網
1.安裝,打開終端,復制粘貼,大約1分鍾左右,下載完成,過程中需要輸入密碼,其他無需任何操作:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.卸載,有安裝就要有卸載,打開終端,復制粘貼:
其實只用把上面安裝的install換成uninstall就行了。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
3.Homebrew 怎么使用?常用命令有哪些?

安裝軟件,如:brew install oclint
卸載軟件,如:brew uninstall oclint
搜索軟件,如:brew search oclint
更新軟件,如:brew upgrade oclint
查看安裝列表, 如:brew list
更新Homebrew,如:brew update
使用brew安裝wget:
brew install wget
秘籍一:使用wget更新hosts
wget https://raw.githubusercontent.com/racaljk/hosts/master/hosts -qO /tmp/hosts && sudo sh -c 'cat /tmp/hosts > /etc/hosts'

 


免責聲明!

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



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