How having multiple Ruby interpreters affects Passenger
Relevant selection for this article:
Passenger may be installed with any Ruby interpreter. Once installed, you can run Passenger's Ruby parts under any Ruby interpreter you want, even if that Ruby interpreter was not the one you originally installed Passenger with.
The reason for this is that Passenger does not dynamically link to Ruby: Passenger uses Ruby entirely out-of-process. Thus you can switch to any Ruby interpreter you want during runtime, without recompiling Passenger, and without worrying about what Ruby you used to install Passenger.
Passenger is also capable of running Ruby web applications under any Ruby interpreter you want. So it is not important which Ruby you use to install Passenger: it will work regardless. Please refer to the documentation for the passenger_ruby
directive to learn how run different web applications under different Ruby interpreters.
Caveat: RVM and RVM gemsets
There is however one caveat if you happen to be using RVM or RVM gemsets. When you gem install
Passenger using RVM, then RVM will install Passenger into the currently active RVM Ruby and gemset. This means that Passenger commands - such as passenger
, passenger-install-xxx-module
and passenger-status
- are available in that same RVM Ruby and gemset only. When you switch Ruby interpreter, or when you switch gemset, the Passenger commands will no longer be available, and you will get a command not found
error. Here's an example which demonstrates the problem.
## Install Passenger (open source edition) using Ruby 1.9.3 ## and the 'business' gemset $ rvm use 1.9.3 Using /home/phusion/.rvm/gems/ruby-1.9.3-p429 $ rvm gemset create business $ rvm gemset use business Using ruby-1.9.3-p429 with gemset business $ curl -O https://s3.amazonaws.com/phusion-passenger/releases/gem_bootstrap.sh $ eval "`sh gem_bootstrap.sh`" $ gem install passenger ## Verify that passenger works $ passenger --version Phusion Passenger version 4.0.14 ## Switch to a different RVM gemset. You will get a `command not found` $ rvm gemset use default Using ruby-1.9.3-p429 with gemset default $ passenger --version bash: passenger: command not found ## Switch to a different Ruby interpreter. You will also get ## a `command not found` $ rvm use 2.0.0 Using /home/phusion/.rvm/gems/ruby-2.0.0-p195 $ passenger --version bash: passenger: command not found ## Switch back to the Ruby and gemset that you installed ## Passenger with, and verify that it works again $ rvm use 1.9.3 Using /home/phusion/.rvm/gems/ruby-2.0.0-p195 $ rvm gemset use business Using ruby-1.9.3-p429 with gemset business $ passenger --version Phusion Passenger version 4.0.14
There are several ways to solve this problem:
-
Permanently add Passenger's command directory to your PATH, so that your shell can always find them even when you switch RVM Ruby or gemset. If you don't know what PATH means, please read About environment variables first.
The drawback is that you have to redo this every time you upgrade Passenger, because the Passenger directory filename is dependent on the version number.
First, identify the location of the Passenger command directory, like this:
$ echo `passenger-config --root`/bin /home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin
Next, add the directory that you've found to your current shell's PATH:
export PATH=/home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin:$PATH
Finally, make the change permanent by appending the above command to your bash startup file:
echo 'export PATH=/home/phusion/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.15/bin:$PATH' \ >> ~/.bashrc
- Switch back to the RVM Ruby and gemset that you installed Passenger with, before running any Passenger command.
-
Prepend any Passenger command with
rvm-exec RUBY_NAME@GEMSET_NAME ruby -S
. If the relevant Passenger command also needs root privileges, then prependrvmsudo
before that. For example:rvm-exec 1.9.3@business ruby -S passenger --version rvmsudo rvm-exec 1.9.3@business ruby -S passenger-install-apache2-module