bash 如何在 OS X 上安装 Homebrew?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20381128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 00:29:52  来源:igfitidea点击:

How to install Homebrew on OS X?

macosbashinstallhomebrew

提问by dwstein

I'm trying to install Homebrew on OS X.

我正在尝试在 OS X 上安装 Homebrew。

According to the Homebrew site I should type

根据 Homebrew 网站,我应该输入

brew install wget

and all I get is

我得到的只是

-bash: brew: command not found

So I've searched StackOverflow and found this answer. The problem, however, is I don't see brewin /usr/local/bin.

所以我搜索了 StackOverflow 并找到了这个答案。但问题是我没有看到brew/usr/local/bin

So, I also added the following line to my .bashrcfile

所以,我还在我的.bashrc文件中添加了以下行

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

But I'm still getting the command not founderror.

但我仍然收到command not found错误。

How do I get Homebrew installed on OS X?

如何在 OS X 上安装 Homebrew?

回答by Jay Harris

It's on the top of the Homebrew homepage.

它位于Homebrew 主页的顶部。

From a Terminal prompt:

从终端提示:

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

The command brew install wgetis an example of how to use Homebrew to install another application (in this case, wget) after brew is already installed.

该命令brew install wget是在安装wgetbrew 后如何使用 Homebrew 安装另一个应用程序(在本例中为)的示例。

回答by Viji

Check if Xcode is installed or not:

检查是否安装了 Xcode:

$ gcc --version

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

$ brew doctor

$ brew update

http://techsharehub.blogspot.com/2013/08/brew-command-not-found.html"click here for exact instruction updates"

http://techsharehub.blogspot.com/2013/08/brew-command-not-found.html“单击此处获取准确的说明更新”

回答by drishti ahuja

I might be late to the party, but there is a cool website where you can search for the packages and it will list the necessary command to install the stuff. BrewInstallis the website.

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

However you can install wget with the following command:

但是,您可以使用以下命令安装 wget:

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

Hope this helps :)

希望这可以帮助 :)

回答by ximbal

On an out of the box MacOS High Sierra 10.13.6

开箱即用的 MacOS High Sierra 10.13.6

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

Gives the following error:

给出以下错误:

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.

curl 默认使用证书颁发机构 (CA) 公钥 (CA 证书) 的“捆绑”执行 SSL 证书验证。如果默认包文件不够用,您可以使用 --cacert 选项指定备用文件。

如果此 HTTPS 服务器使用由捆绑中表示的 CA 签署的证书,则证书验证可能因证书问题而失败(它可能已过期,或者名称可能与 URL 中的域名不匹配)。

如果您想关闭 curl 对证书的验证,请使用 -k(或 --insecure)选项。

HTTPS-proxy 有类似的选项 --proxy-cacert 和 --proxy-insecure。

Solution: Just add a kto your Curl Options

解决方案:只需在您的 Curl 选项中添加一个k

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

回答by ccpizza

Here is a version that wraps the homebrew installer in a bash function that can be run from your deployment scripts:

这是一个将 homebrew 安装程序包装在 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
}

And another function which will install a homebrew formula if it is not already installed:

如果尚未安装自制程序,则另一个功能将安装它:

brew_install () {       
    if brew ls --versions  > /dev/null; then
        echo "already installed: "
    else
        echo "Installing forumula: ..."
        brew install 
    fi
}

Once you have these functions defined you can use them as follows in your bash script:

一旦定义了这些函数,您就可以在 bash 脚本中按如下方式使用它们:

install_homebrew_if_not_present
brew_install wget
brew_install openssl
...

回答by Rajesh Maurya

If you still get error after running,

如果运行后还是报错,

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

Then try to download and install command line tool from https://developer.apple.com/download/more/for your particular Mac os and Xcode version.

然后尝试从https://developer.apple.com/download/more/为您的特定 Mac os 和 Xcode 版本下载并安装命令行工具。

Then try to run,

然后试着跑,

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

and then

进而

brew install node

回答by Ramprasath Selvam

Open Terminal and put below command.
Install:

打开终端并输入以下命令。
安装:

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

Uninstall:

卸载:

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

Once install complete after entering brew commands:

输入brew命令后安装完成:

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

回答by Jayprakash Dubey

You can install brew using below command.

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

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

However, while using this you will get warning that it buy homebrew installer is now deprecated. Recommended to use Bash instead.

但是,在使用它时,您会收到警告,提示它购买自制安装程序现已弃用。建议改用 Bash。

Screenshot 1

截图 1

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

Screenshot 2

截图 2

回答by James N

add the following in your terminal and click enter then follow the instruction in the terminal. /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

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

回答by Harshad

Following command doesn't work if your are under proxy.

如果您使用代理,则以下命令不起作用。

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

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

Instead user following -

而是用户关注 -

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

Note we have to use %5c instead of "\" Similarly if your password has any special character replace it with unicode e.g for @ use %40 Refer this Unicodes

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

Replace above command with your own params

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

DOMAIN - Your Domain

域 - 您的域

USER_NAME - Your User Name

USER_NAME - 您的用户名

PASSWORD - password

密码 - 密码

PROXY - 10.10.10.10

代理 - 10.10.10.10

PORT - 8080

端口 - 8080