用自制安装Ruby(Installing Ruby with Homebrew)

2019-06-27 20:28发布

我用自制安装了Ruby:

brew install ruby

在“注意事项”,它说:

注:默认情况下,宝石安装的二进制文件将被放置到:
/usr/local/Cellar/ruby/1.9.3-p194/bin

您可能想要将它添加到您的PATH。

这是什么意思,我怎么可以把它添加到我的“路径”? 假设它有一个.bash_profile中,但新本做。

Answer 1:

~/.bash_profile添加以下行

export PATH=/usr/local/Cellar/ruby/1.9.3-p194/bin:$PATH

当您完成后,关闭终端并重新打开它。 你应该罚款。

另外,您也可以执行在每个开壳,而不是关闭/重新开放的follwing:

source ~/.bash_profile

注:我通过强烈建议安装Ruby RVM或rbenv这样你就可以管理多个Ruby版本和使用gemsets。



Answer 2:

该行添加到您的.profile文件(或.bash_profile文件,.bashrc中,.zshrc,等):

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

这是一个先进的最新版本凯尔的答案 。 随着2014年5月的, brew info ruby打印:

默认情况下,创业板安装的可执行文件将被放置到:

  /usr/local/opt/ruby/bin

您可能想要将它添加到您的PATH。 经过升级,可以运行

  gem pristine --all --only-executables

...恢复binstubs已安装的宝石。



Answer 3:

快速解决:

打开/ etc /路径。

Change the order of lines(highest priority on top).
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin


Answer 4:

安装Ruby:

brew install ruby

我建议设置$ PATH,$ GEM_PATH和$ GEM_HOME。 对于最新的Ruby是:

export PATH=/usr/local/opt/ruby/bin:$PATH
export GEM_HOME=/usr/local/opt/ruby/lib/ruby/gems/2.6.0
export GEM_PATH=/usr/local/opt/ruby/lib/ruby/gems/2.6.0

把它们放在像~/.bash_profile

然后去验证:

type -a ruby
> ruby is /usr/local/opt/ruby/bin/ruby
> ...

ruby -v
> ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]

gem list
> *** LOCAL GEMS ***
> 
> did_you_mean (1.3.0)
> minitest (5.11.3)
> ...


Answer 5:

在红宝石的2.6.x, brew info ruby说:

By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/2.6.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

我不想每次红宝石被更新来更新XXshrc。 我zshrc是:

if [ -d "/usr/local/opt/ruby/bin" ]; then
        export PATH=/usr/local/opt/ruby/bin:$PATH
        export PATH=`gem environment gemdir`/bin:$PATH
fi


文章来源: Installing Ruby with Homebrew