Installing Ruby with Homebrew

2019-01-17 00:39发布

I installed Ruby with Homebrew:

brew install ruby

Under "Caveats" it said:

NOTE: By default, gem installed binaries will be placed into:
/usr/local/Cellar/ruby/1.9.3-p194/bin

You may want to add this to your 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.

4条回答
Fickle 薄情
2楼-- · 2019-01-17 00:48

Install ruby:

brew install ruby

I'd recommend setting $PATH, $GEM_PATH and $GEM_HOME. For latest Ruby it's:

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.

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)
> ...
查看更多
Viruses.
3楼-- · 2019-01-17 00:56

in ~/.bash_profile add the following line

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:

source ~/.bash_profile

Note: I highly recommend installing ruby via rvm or rbenv so you can manage multiple ruby versions and use gemsets.

查看更多
Anthone
4楼-- · 2019-01-17 01:07

Add this line to your .profile (or .bash_profile, .bashrc, .zshrc, etc):

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

This is an up-to-date version of Kyle's answer. As of May 2014, brew info ruby prints:

By default, gem installed executables will be placed into:

  /usr/local/opt/ruby/bin

You may want to add this to your PATH. After upgrades, you can run

  gem pristine --all --only-executables

...to restore binstubs for installed gems.

查看更多
在下西门庆
5楼-- · 2019-01-17 01:09

Quick fix:

Open /etc/paths.

Change the order of lines(highest priority on top).
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
查看更多
登录 后发表回答