RVM has been a great tool for managing different projects with different ruby versions – for you python folks you may be aware of virtualenv. But that has not come without it’s issues. Setting up Jenkins CI and RubyMine can require some extra setup steps that are a little frustrating sometimes. I’ve started moving all my development environments to rbenv and have been very happy. rbenv is a bit less intrusive and simpler to manage.
Here are the steps I took to make that move. Hopefully this will make things easy when you decide to make the switch.
The steps here assume you’re on a Mac with homebrew. If not, you may need to do some installation from source.
First – blow away rvm.
rvm implode rm ~/.rvmrc rm -r ~/.rvm
Install rbenv.
# install rbenv with homebrew brew install rbenv
Install ruby-build. This plugin gives rbenv the install action to install rubies.
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Install rbenv-bundler. This will make rbenv bundler aware. Without, you may run into permissions issues because without it ‘gem install bundler’ tries to install into /usr/bin.
git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
Add shims to every shell by adding this line to your .profile or .bashrc
eval "$(rbenv init -)"
And while you’re in there, you might also remove references to rvm. Mine was trying to run ~/.rvm/script/rvm and had ~/.rvm/bin in the PATH. I removed all that and started with a clean shell for the rest.
Install your rubies
rbenv install 1.8.7-p334 rbenv install 1.9.2-p180 # ... add others that you use here
You can run
rbenv install --list
to figure out what rubies ruby-build knows about.
Pick a system ruby
rbenv global 1.9.2-p180
Setup bundler. I’m not certain that you need to do this for each ruby, but I had problems without doing that. So for good measure, and since it only has to happen once:
rbenv shell 1.8.7-p334 gem install bundler rbenv shell 1.9.2-p190 gem install bundler rbenv rehash
Tell rbenv that you’ve got new stuff
rbenv rehash
Set rubies for your different levels of usage. You can set global, local, and shell. I primarily use global and local, where global is for the machine, and local is for the projects that I work on.
cd /projects/my-1.8.7-project/ rbenv local 1.8.7-p334 cd /projects/my-1.9.2-project/ rbenv local 1.9.2-p190
That should be it.
You’ll need to re-bundle on your projects but from there on out you should be happily moved onto rbenv.
I’ve only just begun the process. For my development machines, this has been an easy switch. I’m hoping it will help me clean up my config for Jenkins.
Also, keep in mind that if you share projects with RVM users, no problem. These two systems, though they don’t work well together on the same machine, will not conflict across boxes. So you can safely run rbenv while your co-workers use rvm.
I followed same way to migrate rbenv from rvm. Everything is ok on the shell but I get the error “bundle: command not found” when job is building. Have an idea about this problem?
I know its temporary solution but I added export PATH=”$HOME/.rbenv/bin:$PATH” and eval “$(rbenv init -)” lines in Jenkins execute shell.
I suspect it’s because either you didn’t do the gem install bundler or that you forgot to rehash
Because of the path and the way rbenv handles executables, if you make updates to your environment, you need to run the ‘rehash’ command so rbenv will add new shims and make those executables available.