Installing Ruby with Homebrew
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.
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)
> ...
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.