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'

原文地址:https://www.cnblogs.com/zdz8207/p/mac-brew-install.html