layout: post title: RVM, Passenger 3, REE, Rails3 in a Debian date: 2011-01-03 03:16:23.000000000 +00:00 categories:

  • Linux
  • Rails tags:
  • passenger
  • ree
  • ruby
  • rvm

    This post explains how to install a global RVM (Ruby Version Manager) with Passenger 3 gem, Ruby Enterprise Edition in a Debian server machine for all users.

  1. Create /etc/rvmrc with the contents:
export rvm_path="/opt/rvm"
export rvm_source_path="${rvm_path}/src"
export rvm_log_path="${rvm_path}/log"
export rvm_bin_path="${rvm_path}/bin"
export rvm_gems_path="$rvm_path/gems"
export rvm_tmp_path="${rvm_tmp_path:-"$rvm_path/tmp"}"
export rvm_install_on_use_flag=0
export rvm_gemset_create_on_use_flag=0
# export rvm_make_flags="-j7"
export rvm_trust_rvmrcs_flag=1
export rvm_pretty_print_flag=1

I have chosen /opt/rvm/ for the installation.

  1. To install RVM, use the cool script provided on rvm’s site:
bash < <(curl
  1. To enable RVM in the command-line, add this to /etc/profile at the very end:
[[ -s "/opt/rvm/scripts/rvm" ]] && source "/opt/rvm/scripts/rvm"

Be sure to modify the path /opt/rvm if you have installed rvm elsewhere.

  1. Re-login to enable rvm command. Now we have RVM environment installed and we will take care of Ruby Enterprise Edition.
  2. Installing Ruby Enterprise Edition
rvm install ree
  1. Installing Passenger 3.
rvm ree
#installing the gem
gem install passenger
#compiling Apache2 module
  1. Now add/change the paths how Passenger is loaded in /etc/apache2/mods-available/ in the files passenger.load and passenger.conf:
LoadModule passenger_module /opt/rvm/gems/ree-1.8.7-2010.02/gems/passenger-3.0.2/ext/apache2/
PassengerRoot /opt/rvm/gems/ree-1.8.7-2010.02/gems/passenger-3.0.2
PassengerRuby /opt/rvm/wrappers/ree-1.8.7-2010.02/ruby

Next enable the module with a2enmod passenger and restart apache. You can verify if Passenger started with grep:

server:~# ps aux | grep Passenger
root     10515  0.0  0.3   4164  1676 ?        Ssl  02:25   0:00 PassengerWatchdog
root     10519  0.0  0.3  12868  1920 ?        Sl   02:25   0:00 PassengerHelperAgent
root     10521  0.1  1.5  17720  7812 ?        S    02:25   0:00 Passenger spawn server
nobody   10524  0.0  0.6   9504  3088 ?        Sl   02:25   0:00 PassengerLoggingAgent
  1. Next, we will make the REE the default environment and create a default gemset.
#switch to REE
rvm use ree
#create the gemset
rvm gemset create default
#use the gemset and set it as default
rvm use ree@default --default
#install rails3 in the gemset
gem install rails3

If you want normal users to be able to create gemsets and install additional gems, you have to change permissions of /opt/rvm/gems/. This is not very elegant and super-safe solution, but for development machines is ok.

chmod -R 777 /opt/rvm/gems/

Using RVM in CRON If you try to use RVM in cron the normal way, like:

37 * * * *      /bin/bash -l -c "RAILS_ENV=production /opt/rvm/bin/rake db:backup;"

You will end up with one of the following errors:

command rvm is not found command rake is not found gem XXX is not found

This is due to the fact, that cron commands are run in a very limited environment whereas RVM heavily relies on the environment variables. As a remedy for that situation, you have to invoke bash as if it was invoked by a login shell:

38 * * * * 	/bin/bash -l -c "cd project; RAILS_ENV=production rake db:backup;"


-l is invoking bash with full environment for RVM to work properly. Remember to put the appropriate RVM loading line in the .bashrc ! -c says read the command from the parameter next in the command, you cd to the project directory; this is needed to set up proper RVM environment from the .rvmrc file - so yes, I am assuming you have a file named .rvmrc in your project directory inside which you are selecting the proper gemset