根据Homebrew网站,要安装它,我需要输入:
brew install wget
我得到一个错误消息:
-bash: brew: command not found
找到了这个答案。然而,问题是我在/usr/local/bin中没有看到brew。
我在.bashrc文件中添加了下面这行代码
export PATH=/usr/local/bin:$PATH
仍然得到命令未找到错误。
如何在macOS上安装Homebrew ?
根据Homebrew网站,要安装它,我需要输入:
brew install wget
我得到一个错误消息:
-bash: brew: command not found
找到了这个答案。然而,问题是我在/usr/local/bin中没有看到brew。
我在.bashrc文件中添加了下面这行代码
export PATH=/usr/local/bin:$PATH
仍然得到命令未找到错误。
如何在macOS上安装Homebrew ?
当前回答
不知道为什么没有人提到这一点:当你从官方网站运行安装命令时,在最后几行你会看到如下内容,你需要遵循==>下一步:
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Add Homebrew to your PATH in /Users/{YOUR USER NAME}/.bash_profile:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/{YOUR USER NAME}/.bash_profile
eval $(/opt/homebrew/bin/brew shellenv)
这是bash shell的。对于每个不同的shell,您将看到不同的步骤,但是这些步骤的源是相同的。
其他回答
检查是否安装了Xcode:
$ gcc --version
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ brew doctor
$ brew update
http://techsharehub.blogspot.com/2013/08/brew-command-not-found.html“点击这里获取准确的指令更新”
如果运行后仍然报错,
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后尝试从https://developer.apple.com/download/more/下载并安装命令行工具,适用于特定的Mac os和Xcode版本。
然后试着跑,
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后
brew install node
下面是一个将自制程序安装程序包装在bash函数中的版本,可以从部署脚本中运行:
install_homebrew_if_not_present() {
echo "Checking for homebrew installation"
which -s brew
if [[ $? != 0 ]] ; then
echo "Homebrew not found. Installing..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
echo "Homebrew already installed! Updating..."
brew update
fi
}
另一个函数将安装一个自制公式,如果它还没有安装:
brew_install () {
if brew ls --versions $1 > /dev/null; then
echo "already installed: $1"
else
echo "Installing forumula: $1..."
brew install $1
fi
}
一旦你定义了这些函数,你可以在你的bash脚本中像下面这样使用它们:
install_homebrew_if_not_present
brew_install wget
brew_install openssl
...
首先,在MAC终端上粘贴命令来安装自制程序
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后编辑你的.bashrc文件
vi .bashrc
在最后粘贴下面的命令并保存它
export PATH=/opt/homebrew/bin:$PATH
要保存,只需输入:wq并按enter
如果bashrc文件不存在,则只需创建并编辑该文件,以创建类型
touch ~/.bashrc
然后简单地运行命令
source ~/.bashrc
现在尝试使用brew命令,希望它现在可以工作了
更新:如果你使用的是M1 mac,那么在安装homebrew后,只需运行下面提到的命令并重新加载终端
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
不知道为什么没有人提到这一点:当你从官方网站运行安装命令时,在最后几行你会看到如下内容,你需要遵循==>下一步:
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Add Homebrew to your PATH in /Users/{YOUR USER NAME}/.bash_profile:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/{YOUR USER NAME}/.bash_profile
eval $(/opt/homebrew/bin/brew shellenv)
这是bash shell的。对于每个不同的shell,您将看到不同的步骤,但是这些步骤的源是相同的。