Documenting the process of moving from RVM to rbenv. Also get some of the
cool tools
working. This intentionally has nothing to do with rails. And none of this
should require sudo. You’ll probably want to consult the individual project
pages at some point to learn more, but this guide should contain every setup
instruction needed for all the tools to work.
(Note that this is a dump of the steps I performed and is not yet fully cleaned up/ordered/tested.)
This little tutorial enables you to install and use multiple versions of ruby, isolate project gems, and automatically use appropriate combinations of rubies and gems.
The two things I really care about in this pursuit are:
- Having at least one reliable locally installed Ruby
- Project-specific Gemsets
(Note that I’m using using Zsh in the examples.)
I’ve loved using RVM. It did do a surreptitious thing with my environment that
I still don’t have a handle on (beyond overriding things with shell
functions). If rbenv can eliminate any of the magic of environment
management, then I’ll give it a go.
As this is a multi-repo configuration, you might want to consider using git magnet
Git it.
% git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
Enable it.
% echo 'eval "$(rbenv init -)"' >> ~/.zshrc # or equivalent
% exec $SHELL
You haven’t done anything interesting yet. Hang tight.
For more rationale details, consult the rbenv
project page.
(skip this) See how it works:
##% which ruby
##/home/mde/.rbenv/shims/ruby
##% <`!!`
##«see that it just runs: rbenv exec ruby …»
% mkdir -p ~/.rbenv/plugins
% cd ~/.rbenv/plugins
% git clone git://github.com/sstephenson/ruby-build.git
Now we’re done manually installing things to specific places.
% cd ~/anywhere
Find out which rubies are available.Wow, you can even tab-complete these:
% rbenv install 1.8.7-p«tab»
1.8.7-p249 1.8.7-p302 1.8.7-p334 1.8.7-p352 1.8.7-p357 1.8.7-p358
Get a few (be patient):
% rbenv install 1.9.3-p125
% rbenv install jruby-1.6.7
% rbenv install rbx-2.0.0 # rubinius; why not
You need to “rehash” to regenerate rbenv’s “shims” after installing a new ruby.
% rbenv rehash
Now do it again for practice:
% rbenv rehash
You're going to do that almost every time you install a gem to generate
the shims. Get used to it or make rbenv install an alias to also rehash.
You’ve probably already got a system ruby installed. See them all now.
(Actually, I believe system ruby is not listed here.)
% rbenv versions
1.8.7-p358
1.9.3-p125 (set by /home/mde/.rbenv/version)
jruby-1.6.7
rbx-2.0.0-dev
Turn one on for persistent “global” use across your system (for your user
anyway). Note to RVM users: forget the verb use. global, local,
and shell are your new enablers.
% rbenv global jruby-1.6.7
% ruby -ve 'puts "it works"'
jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM)…
it works
You might be interested to know that these are all being installed to your
~/.rbenv/versions dir.
Use the rbenv “plugin” subtool rbenv-gemset.
% cd ~/.rbenv/plugins
% git clone git://github.com/jamis/rbenv-gemset.git
You should now have a new command in rbenv:
% rbenv gemset «tab»
active create delete file list version
% rbenv gemset create 1.9.3-p125 helloset
(Note that tab-completion is not yet working for the gemset command.)
That set up a directory for you in
~/.rbenv/versions/1.9.3-p125/gemsets/helloset. But now it’s up to you to do the
other half manually: setting the name of your gemset. In this case it’s
helloset.
% >.rbenv-gemsets
helloset
Now when you gem install (see “Bundler” section below) something it will go
to your helloset gem area.
Looks like you can combine use of multiple gemsets with it.
The big benefit to this setup is enabling each project to use a different set of differently versioned gems.
% cd $TMPDIR/hello
% >.rbenv-gemsets
helloset
Bundler. is the tool for managing your project dependencies. In fact, we’ll never even install a gem directly, without Bundler.
NOTE: Although the tool is called “Bundler,” its tool is actually bundle.
This has caused some confusion. You’ll actually be fine whether you install
the bundle or bundler gem, but the command will alwyas be bundle.
Now that you’re working with multiple rubies, every ruby will need its own bundler.
Now, what gem do we actually have?
% whence -av gem
gem is /home/mde/.rbenv/shims/gem
gem is /usr/bin/gem
That didn’t make it too clear. Every ruby actually provides its own gem
command. Here’s how to see it:
% rbenv which gem
/home/mde/.rbenv/versions/1.9.3-p125/bin/gem
And what Bundler?
% rbenv which bundle
rbenv: bundle: command not found
Hmm. Now we can see that we need to install it manually. So this is
bootstrapping; it’ll be the only time we need to use gem directly for
installing.
% gem install bundler
…
% rbenv which bundle
/home/mde/.rbenv/versions/1.9.3-p125/bin/bundle
Great. That was quick and easy.
% which -a bundle
bundle is /home/mde/.rbenv/shims/bundle
bundle is /usr/bin/bundle
Now do it for all your rubies (and every time you install another ruby).
% for r in
% >Gemfile
source "http://rubygems.org"
gem "sinatra", "1.3.2"
gem "compass", "0.12.1"
% bundle install
% cd ~/proj/foo
% rbenv global 1.9.3-p125
% rbenv local «tab»
1.8.7-p358 1.9.3-p125 jruby-1.6.7 rbx-2.0.0-dev system --unset
% rbenv local jruby-1.6.7
Set a local persistent version.
% rbenv local rbx-2.0.0-dev
% cat .rbenv-version
rbx-2.0.0-dev