[英]Installing Ruby with Homebrew
I installed Ruby with Homebrew: 我用Homebrew安装了Ruby:
brew install ruby
Under "Caveats" it said: 根据“警告”,它说:
NOTE: By default, gem installed binaries will be placed into: 注意:默认情况下,gem安装的二进制文件将放入:
/usr/local/Cellar/ruby/1.9.3-p194/bin /usr/local/Cellar/ruby/1.9.3-p194/binYou may want to add this to your PATH. 您可能希望将其添加到PATH中。
What does that mean and how can I add it to my "path"? 这是什么意思,我怎样才能将它添加到我的“路径”中? Assuming it has to do with a bash_profile but new to this. 假设它与bash_profile有关,但对此却是新的。
in ~/.bash_profile
add the following line 在~/.bash_profile
添加以下行
export PATH=/usr/local/Cellar/ruby/1.9.3-p194/bin:$PATH
When you're done, close your terminal and re-open it. 完成后,关闭终端并重新打开。 You should be fine. 你应该没事。
Alternatively, you can execute the follwing in each open shell instead of closing/re-opening: 或者,您可以在每个打开的shell中执行以下操作,而不是关闭/重新打开:
source ~/.bash_profile
Note: I highly recommend installing ruby via rvm or rbenv so you can manage multiple ruby versions and use gemsets. 注意:我强烈建议您通过rvm或rbenv安装ruby,这样您就可以管理多个ruby版本并使用gemsets。
Add this line to your .profile (or .bash_profile, .bashrc, .zshrc, etc) : 将此行添加到.profile(或.bash_profile,.bashrc,.zshrc等) :
export PATH=/usr/local/opt/ruby/bin:$PATH
This is an up-to-date version of Kyle's answer . 这是Kyle答案的最新版本。 As of May 2014, brew info ruby
prints: 截至2014年5月, brew info ruby
打印:
By default, gem installed executables will be placed into: 默认情况下,gem安装的可执行文件将放入:
/usr/local/opt/ruby/bin
You may want to add this to your PATH. 您可能希望将其添加到PATH中。 After upgrades, you can run 升级后,您可以运行
gem pristine --all --only-executables
...to restore binstubs for installed gems. ...为已安装的宝石恢复binstubs。
Install ruby: 安装红宝石:
brew install ruby
I'd recommend setting $PATH, $GEM_PATH and $GEM_HOME. 我建议设置$ PATH,$ GEM_PATH和$ GEM_HOME。 For latest Ruby it's: 对于最新的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
Put them in something like ~/.bash_profile
. 把它们放在像~/.bash_profile
这样的东西里。
And then to verify: 然后验证:
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)
> ...
Quick fix: 快速解决:
Open /etc/paths. 打开/ etc / paths。
Change the order of lines(highest priority on top).
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
In ruby 2.6.x, brew info ruby
says: 在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"
I don't want to update XXshrc whenever ruby is updated. 我不想在更新ruby时更新XXshrc。 My zshrc is: 我的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.