Ruby-on-rails 如何判断 Mac OS X 上是否安装了自制软件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21577968/
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-02 23:20:03  来源:igfitidea点击:

How to tell if homebrew is installed on Mac OS X

ruby-on-railsmacoshomebrew

提问by Kmb40

I am doing some Rails programming and I consistently see Homebrew referenced in solutions around the web but have never used it.

我正在做一些 Rails 编程,我一直看到网络解决方案中引用了 Homebrew,但从未使用过它。

I also notice Homebrew in the terminal version 2.9 as an option next to "Shell -> New" from the terminal drop down but when I select homebrew and issue commands, they fail.

我还注意到终端版本 2.9 中的 Homebrew 作为终端下拉菜单中“Shell -> New”旁边的选项,但是当我选择 homebrew 并发出命令时,它们失败了。

Usually with the "command not found" error.

通常会出现“找不到命令”错误。

Strangely enough I have been unable to locate a simple command to determine whether brew is installed or not.

奇怪的是,我一直无法找到一个简单的命令来确定是否安装了 brew。

How do I check to see if Homebrew is already installed on my Mac?

如何检查我的 Mac 上是否已安装 Homebrew?

回答by bmargulies

brew help. If brew is there, you get output. If not, you get 'command not found'. If you need to check in a script, you can work out how to redirect output and check $?.

brew help. 如果 brew 在那里,你会得到输出。如果没有,您会收到“未找到命令”。如果您需要签入脚本,您可以弄清楚如何重定向输出并检查$?.

回答by star18bit

I use this to perform update or install:

我用它来执行更新或安装:

which -s brew
if [[ $? != 0 ]] ; then
    # Install Homebrew
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    brew update
fi

回答by Liyan Chang

The standard way of figuring out if something is installed is to use which.

确定是否安装了某些东西的标准方法是使用which.

If Brew is installed.

如果安装了 Brew。

>>> which brew
/usr/local/bin/brew

If Brew is not installed.

如果未安装 Brew。

>>> which brew
brew not found

Note: The "not installed" message depends on your shell. zshis shown above. bashwill just not print anything. cshwill say brew: Command not found.In the "installed" case, all shells will print the path.)

注意:“未安装”消息取决于您的外壳。zsh如上所示。bash不会打印任何东西。csh会说brew: Command not found.在“已安装”的情况下,所有外壳都将打印路径。)

It works with all command line programs. Try which grepor which python. Since it tells you the program that you're running, it's helpful when debugging as well.

它适用于所有命令行程序。尝试which grepwhich python。由于它告诉您正在运行的程序,因此在调试时也很有帮助。

回答by Aamnah

While whichis the most common way of checking if a program is installed, it will tell you a program is installed ONLY if it's in the $PATH. So if your program is installed, but the $PATHwasn't updated for whatever reason*, whichwill tell you the program isn't installed.

虽然which是检查程序是否安装的最常用方法,但它只会告诉您程序是否安装在$PATH. 因此,如果您的程序已安装,但由于$PATH某种原因未更新*,which则会告诉您该程序未安装。

(*One example scenario is changing from Bash to Zshell and ~/.zshrcnot having the old $PATHfrom ~/.bash_profile)

(*一个示例场景是从 Bash 更改为 Zshell 而~/.zshrc没有旧的$PATHfrom ~/.bash_profile

command -v foois a better alternative to which foo. command -v brewwill output nothing if Homebrew is not installed

command -v foo是更好的替代品which foocommand -v brew如果未安装 Homebrew,则不会输出任何内容

command -v brew

Here's a sample script to check if Homebrew is installed, install it if it isn't, update if it is.

这是一个示例脚本,用于检查 Homebrew 是否已安装,如果未安装则安装,如果已安装则更新。

if [[ $(command -v brew) == "" ]]; then
    echo "Installing Hombrew"
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
    echo "Updating Homebrew"
    brew update
fi

回答by TravisP

I just type brew -v in terminal if you have it it will respond with the version number installed.

我只是在终端中输入 brew -v 如果你有它,它会以安装的版本号响应。

回答by bits

[ ! -f "`which brew`" ] && echo "not installed"

Explaination: If brew is not installed run command after &&

说明:如果没有安装 brew 之后运行命令 &&

回答by Thomas David Kehoe

brew doctorchecks if Homebrew is installed and working properly.

brew doctor检查 Homebrew 是否已安装并正常工作。

回答by kaiky25

use either the whichor typebuilt-in tools.

使用whichtype内置工具。

i.e.: which brewor type brew

即:which brewtype brew

回答by Sunny Singh

Once you install Homebrew, type command brew doctorin terminal.

安装 Homebrew 后,在终端中输入命令brew doctor

  • If you get the following message:

    Your system is ready to brew

    then you are good to go and you have successfully installed homebrew.

  • If you get any warnings, you can try fixing it.

  • 如果您收到以下消息:

    您的系统已准备好冲泡

    那么你就可以开始了,你已经成功安装了自制软件。

  • 如果您收到任何警告,您可以尝试修复它。

回答by Yulia

Another one possible way:

另一种可能的方式:

# Check if Ninja is installed
if ! which ninja > /dev/null
then
echo 'Ninja installation...'
brew install ninja
fi