What have you found for these years?

2011-04-22

Installing Ruby 1.9.2 on your Mac

Installing Ruby 1.9.2 on your Mac

Homebrew

I’m assuming you’re using bash, though personally I’m using fish.
If you are already using Homebrew (brew), I would recommend using
Homebrew’s Ruby directly, because it’s simpler. But if you feel
more comfortable with RVM (rvm), it’s ok to use RVM, too. And if
you’re not using Homebrew, than it might be easier that just use RVM.
Here’s the commands to setup everything with Homebrew’s Ruby:

brew update         # make sure brew is updated
brew install ruby   # install ruby 1.9.2
# setup PATH for where gem binaries (executable) are installed.
echo 'export PATH=$(brew --prefix ruby)/bin:$PATH' >> ~/.bash_profile
gem update --system # update rubygems
update_rubygems     # sometimes you'll need this to get fully updated.
gem install bundler # install latest bundler (you shouldn't use sudo)

Actually, personally I have this line in my ~/.gemrc:

gem: --user --no-ri --no-rdoc

So that my gem binaries are installed to ~/.gem/ruby/1.9.1/bin
instead of $(brew --prefix ruby)/bin. Please setup PATH accordingly,
and either way, you won’t need sudo before installing any gems.

To use the original Ruby which is built-in Mac, use /usr/bin/ruby
instead of ruby. If you need to run gem binaries, for example,
bundle, then you’ll need to run it with /usr/bin/ruby -S bundle.
To run rake test, I think either one should work:

/usr/bin/rake test

or

/usr/bin/ruby -S rake test

But, since Rails 2’s script/console was very badly written which
hard coded irb somewhere in its code, so you can’t really run it
with different ruby without some hack. (!!)

RVM

Many people are recommending RVM, indeed it’s good if you really need
multiple versions of Ruby installed. But if you just need one or two
rubies, in my opinion, using RVM makes things a bit more complicated.
Personally, I don’t use RVM, too, since it’s not working correctly
in fish last time I tried. Here’s how I’ll configure RVM:

curl https://rvm.beginrescueend.com/install/rvm | bash # install RVM
source ~/.bash_profile  # reload PATH for rvm
rvm install 1.9.2       # install ruby 1.9.2
rvm --default use 1.9.2 # setup default ruby to 1.9.2
gem update --system     # update rubygems
update_rubygems         # sometimes you'll need this to get fully updated.
gem install bundler     # install latest bundler (you shouldn't use sudo)

To use the original Ruby which is built-in Mac, use:

rvm use system

Then it would pretend that as if RVM were never installed. Since RVM is
really doing some sandboxes stuffs, so if you really need intensively
test the programs under many different rubies, for example, more than
3 or even 4 versions of rubies (1.8.6, 1.8.7, 1.9.1, 1.9.2, trunk, etc),
it would be a lot easier to just go with RVM. Otherwise, I would prefer
vanilla version (official version without any patches).

2 retries:

Anonymous said...

Simple and clear how-to. Especially thanks for this line —
echo 'export PATH=$(brew --prefix ruby)/bin:$PATH' >> ~/.bash_profile

What are benefits using fish shell instead bash or zsh?

Lin Jen-Shin (godfat) said...

Sorry, I am not sure if it's you deleted your message, or it's blogger deleted it. If it's the latter, I can re-paste your comments.

Here's my reply written yesterday but can't post it due to blogger's outage.

* * *

Thanks, glad to know it's helpful.

Regarding fish shell, in short, it's a lot easier and
convenient to use out-of-the-box without custom
configuration. To name a few, syntax highlight,
helpful error messages, no issues using colorful
prompt, (I can't get bash colorful prompt right,
cursor position would be wrong if the line is too
long, totally no idea how to fix that.), and fish
script is a lot more sane than bash, too. Though
personally I avoid writing any shell scripts at all.

But the best thing in fish is its history searching.
Suppose you have this fish_history:

cd ~
ssh 123.123.123.123
gem install ripl-rc
rake test
rake test
rake test
rake test
brew install ruby
ls

Then you can type `install` and press [up],
it would bring you `brew install ruby` with install
highlighted first. Then if you press [up] again,
it will bring you `gem install ripl-rc` and
highlighting install as well. You can also type
`ssh` and press [up], it will bring you
`ssh 123.123.123.123`. So I don't have to remember
any complex command, just type a fragment and
then press [up] [up] to find it. Also, searching
for `rake` would only give you once `rake test`,
instead of multiple times.

The only drawback that I can't really stand is,
on Mac, fish sometimes would hang. I don't know
why, and I've heard that it's totally fine on Linux.

But that might be the past. Someone has a patch
in Homebrew which would be applied if you're installing
fish via Homebrew. This patch reduces some timeout,
and it seldom hang now.

bash is stable, fast, and widely supported. Personally
I run fish on top of bash without using chsh actually...
You can find it here: bash/profile

I didn't use zsh or tcsh much though, so can't
say anything about them. I only remembered from last
time I tried a bunch of shells, bash and fish was
the ones left I was picking from.

Post a Comment

Note: Only a member of this blog may post a comment.



All texts are licensed under CC Attribution 3.0