根据Homebrew网站,要安装它,我需要输入:

brew install wget

我得到一个错误消息:

-bash: brew: command not found

找到了这个答案。然而,问题是我在/usr/local/bin中没有看到brew。

我在.bashrc文件中添加了下面这行代码

export PATH=/usr/local/bin:$PATH

仍然得到命令未找到错误。

如何在macOS上安装Homebrew ?


就在家酿网站主页的顶部。

终端提示符:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

命令brew install wget演示了如何在已经安装brew之后使用Homebrew安装另一个应用程序(在本例中是wget)。


历史……

在大约2020年之前,Homebrew页面上给出的命令是:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

检查是否安装了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“点击这里获取准确的指令更新”

在终端中添加以下内容,单击“enter”,然后按照终端中的说明操作。/usr/bin/ruby -e "$(curl - ssl https://raw.githubusercontent.com/Homebrew/install/master/install)"

下面是一个将自制程序安装程序包装在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
...

在一个开箱即用的MacOS High Sierra 10.13.6

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

给出以下错误:

curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option. HTTPS-proxy has similar options --proxy-cacert and --proxy-insecure.

解决方案:只要在你的卷曲选项中添加一个k

$ ruby -e "$(curl -fsSLk https://raw.githubusercontent.com/Homebrew/install/master/install)"

我可能迟到了,但是有一个很酷的网站,你可以在那里搜索软件包,它会列出安装这些东西的必要命令。 BrewInstall是网站。

但是你可以用下面的命令安装wget:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install wget

希望这对你有所帮助。

在我尝试了所描述的一切之后,我查看了/usr/local/etc/ brew文件夹权限。不知何故,权限被更改了,我无法打开文件夹。我改变了文件夹权限(用chmod)与其他文件夹的权限相同,并开始工作。

如果您在代理下,以下命令将不起作用。

ruby -e "$(curl - ssl https://raw.githubusercontent.com/Homebrew/install/master/install)"

相反,用户关注

ruby -e "$(curl -x http://DOMAIN%5cUSER_NAME:PASSWORD@PROXY:PORT -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

请注意,我们必须使用%5c而不是“\”同样,如果您的密码有任何特殊字符,请将其替换为unicode,例如@使用%40 参考本unicode

用你自己的参数替换上面的命令

域名-你的域名

USER_NAME—您的用户名

PASSWORD -密码

Proxy - 10.10.10.10

端口- 8080

剧本如下:

- usr/bin/ruby -e“curl -fsSL” https://raw.githubusercontent.com/Homebrew/install/master/install)”

如果运行后仍然报错,

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

打开终端,输入下面的命令。 安装:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

卸载:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

一旦安装完成后,输入brew命令:

brew install wget
brew install node
brew install watchman
...
...

您可以使用以下命令安装brew。

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

然而,当使用这个你会得到警告,它购买自制安装程序现在已弃用。建议改用Bash。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Brew现在已经用Bash重写了!

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

如何设置你的Mac为家酿

步骤1

检查你已经安装了Xcode。在终端上运行下面的命令

/usr/bin/xcodebuild -version

它将打印以下示例输出:

Xcode 12.3 Build version 12C33

步骤2

现在打开Xcode:

选择偏好 选择位置选项卡 现在在命令行工具中从下拉菜单中选择你的Xcode版本

步骤3

在终端运行以下命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

注意:如果你有M1芯片Mac运行下面的命令,关闭终端,再打开终端

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

我在mac BigSur M1处理器上安装Homebrew时遇到了同样的brew命令找不到的问题。

I -安装XCode,如果它还没有安装。

II -选择终端。应用程序在Finder。

III -人民币点击终端,选择“获取信息”

IV -选中“使用Rosetta打开”复选框。

关闭所有打开的终端窗口。

打开一个新的终端窗口,安装Hobebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

测试自制软件的安装。

IIX -取消勾选使用Rosetta打开复选框。

macOS 大苏尔

必须将此添加到终端cmd,以使Brew运行。

将Homebrew添加到/Users/*username/.zprofile中的PATH: echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/*username/.zprofile Eval $(/opt/homebrew/bin/brew shellenv)

*username =您的本地机器用户名

不知道为什么没有人提到这一点:当你从官方网站运行安装命令时,在最后几行你会看到如下内容,你需要遵循==>下一步:

==> 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,您将看到不同的步骤,但是这些步骤的源是相同的。

解决“-bash: brew:命令未找到”问题

将Homebrew添加到/Users//.bash_profile中的PATH:

echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users//.bash_profile . sh

eval $(/opt/homebrew/bin/brew shellenv)

首先,在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

如果你使用的是m1芯片mac,那么在安装homebrew后运行以下命令并再次打开终端:

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc

对于带有Apple Silicon (M1)的Mac,导出要运行brew命令的shell路径并进入该路径。

export PATH=/opt/homebrew/bin:$PATH
brew

对于m1 mac,使用该命令重新启动终端。

echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc .

对我有用的是设置BREW_FILE_DIRECTORY,如下所示

echo "export BREW_FILE_DIRECTORY=/opt" >> ~/.zshrc .

因为brew.sh文件在/opt/homebrew/bin下 在脚本中,所有内容似乎都是从BREW_FILE_DIRECTORY变量计算出来的。这在MacBook Pro (M1)上是可行的

在macOS上安装自制程序

要安装自制程序,你可以简单地在终端上运行这个命令…

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

如果你需要帮助安装任何包从自制这个页面应该有帮助