Ruby Version Manager (RVM)

RVM is a command line tool which allows us to easily install, manage and work with multiple Ruby environments from interpreters to sets of gems. For more information see

If you're here because your app requires Ruby 1.9, we recommend using our Ubuntu Ruby NG Packages which provides Ruby 1.9.3 and Rubygems 1.8. We generally do not recommend using RVM in production.


Before we go any further, we need to install some dependencies for RVM.

$ sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core \
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev \
libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison

Installing RVM

These instructions show how to install RVM as the rails user on a Brightbox (not globally), making it easy to remove again in the future. The instructions are suitable for both Lucid and Hardy based Brightboxes, the given commands should be run as the rails user.

First, install the latest version of RVM using the automated installer. This clones the RVM git repository and does some initial preparation and configuration for your environment.

$ curl -L | bash -s stable

Next, edit your bash_profile to ensure RVM is loaded when starting a shell.

$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
$ source ~/.bash_profile

You're now ready to install the desired Ruby versions using RVM and choose a default.

$ rvm install 1.8.7
$ rvm use 1.8.7
$ rvm install 1.9.2
$ rvm use --default 1.9.2

Note: for 32-bit Ubuntu Hardy boxes, you must append '-C –build=i386-linux' to ensure Ruby is built correctly as 32-bit, like so.

rvm install ruby-1.9.2 -C --build=i386-linux

Verify the installation was successful and the expected Ruby version is indeed the default.

$ ruby -v

That's it! You're now ready to go ahead and start using your new Ruby environments. You should install any required gems etc.

Using RVM with Phusion Passenger

You may select exactly one Ruby to run all of your Passenger Ruby applications with. If you need to run more than one Ruby interpreter then you should choose the most common one as Passenger Ruby, for your other apps you'll need to use mod_proxy for apache with Passenger standalone or Mongrel etc.

Before installing the passenger gem, switch to the appropriate Ruby version with RVM.

rvm use 1.9.2

Install the passenger gem and run the installation script to build the module

$ gem install passenger
$ rvmsudo /home/rails/.rvm/gems/<ruby version>/bin/passenger-install-apache2-module

At this point, if you're missing any of the required dependencies the installer will halt and ask you to install them first before continuing. Once the passenger gem is installed for your desired Ruby environment, we need to tell apache where to find it.

Open /etc/apache2/mods-available/passenger.load in your favourite editor and set the LoadModule directive to point at the newly installed passenger module like below. You should switch <ruby version> and <passenger version> for the newly installed Ruby and passenger versions respectively.

LoadModule passenger_module /home/rails/.rvm/gems/<ruby version>/gems/<passenger version>/ext/apache2/

Open /etc/apache2/mods-available/passenger.conf and update the PassengerRoot and PassengerRuby directives also

PassengerRoot /home/rails/.rvm/gems/<ruby version>/gems/
PassengerRuby /home/rails/.rvm/wrappers/<ruby version>/ruby

You're now ready to restart apache so the changes take effect.

$ sudo /etc/init.d/apache2 restart

That's it! Passenger will now load the Ruby version specified by PassengerRuby for your apps.

Deploying with RVM and the Brightbox gem / Capistrano

To ensure the correct Ruby environment is used at deploy time, we need to overwrite the default environment. To do so edit config/deploy.rb in your app root and add the following, replacing <ruby version> with the desired Ruby environment.

set :default_environment, {
  'PATH' => "/home/rails/.rvm/gems/<ruby version>/bin:/home/rails/.rvm/bin:/home/rails/.rvm/rubies/<ruby version>/bin:$PATH",
  'RUBY_VERSION' => '<ruby version>',
  'GEM_HOME' => '/home/rails/.rvm/gems/<ruby version>',
  'GEM_PATH' => '/home/rails/.rvm/gems/<ruby version>',

Using cron with RVM

If you need to use the cron daemon to schedule rake tasks for an app that's using RVM, you'll need to add the following line to your crontab to ensure your cron jobs are executed with the correct environment variables for RVM.


Removing RVM

If you followed the instructions above, removing RVM is as simple as removing the RVM directory for $HOME

$ rm -r ~/.rvm

Reverting Passenger configuration

Don't forget, if you've changed the passenger configuration to use a Ruby environment from RVM, you'll need to revert it to use the packaged version installed on your Brightbox by editing the module config like so


LoadModule passenger_module /usr/lib/apache2/modules/


PassengerRoot /usr
PassengerRuby /usr/bin/ruby
docs/rvm.txt · Last modified: 2012/05/10 18:30 by johnleach