我用 Homebrew 安装了 Ruby:
brew install ruby
在“注意事项”下,它说:
注意:默认情况下,gem 安装的二进制文件将放置在:
/usr/local/Cellar/ruby/1.9.3-p194/bin您可能希望将其添加到您的 PATH 中。
这是什么意思,我怎样才能将它添加到我的“路径”中?假设它与一个 bash_profile 有关,但对此是新的。
将此行添加到您的 .profile(或 .bash_profile、.bashrc、.zshrc 等):
export PATH=/usr/local/opt/ruby/bin:$PATH
这是凯尔答案的最新版本。截至 2014 年 5 月,brew info ruby
打印:
默认情况下,gem 安装的可执行文件将被放置到:
/usr/local/opt/ruby/bin
您可能希望将其添加到您的 PATH 中。升级后可以运行
gem pristine --all --only-executables
...恢复已安装 gem 的 binstubs。
安装红宝石:
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)
> ...
快速解决:
打开 /etc/paths。
Change the order of lines(highest priority on top).
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
在 ruby 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"
每当更新 ruby 时,我都不想更新 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