We use CentOS almost exclusively here at Nexcess.net and while it’s very stable, a downside is that it often ships with older versions of software. Unfortunately, Ruby is one of those older software packages that we find our clients will need updated (for Ruby on Rails). Googling reveals that compiling the newer version of ruby from source is a common solution, but we’ve found one we like better RVM.
RVM installation in a shared environment is pretty simple, with most of the process being explained in RVM’s own documentation but to make things easy, I will explain here (“#” denotes that the command is run as root, “$” is for user commands)
1) Run the RVM installer (as root).
# bash < <(curl -sk https://rvm.beginrescueend.com/install/rvm)
This will install RVM into “/usr/local/rvm”.
*Note* I ran into a bug in the installer here and the /usr/local/rvm/scripts/ directory was missing after running the installer. The solution was to clone the GitHub repo and replace the /usr/local/rvm directory with the cloned repo directory, then remove the .git/ directory and rename the new /usr/local/rvm/binscripts/ directory to just /usr/local/rvm/bin/.
2) To activate RVM, we source the rvm script “/usr/local/rvm/scripts/rvm” with (it’s
recommended that you add this to your .bashrc file so it’s always available):
# source /usr/local/rvm/scripts/rvm
You can check that everything worked ok by running:
# type rvm | head -1
The output should be “rvm is a function”.
3) Now we can install the new version of Ruby, but we need it’s build dependancies first:
# yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 iconv-devel
then we can go ahead with the Ruby install (this can take a while):
# rvm install 1.8.7
4) Great, now Ruby 1.8.7 is installed, but how do we use it? Well, how this part goes depends on how you plan to use it. We need it for RoR via mod_passenger so we need install the passenger gem, then compile mod_passenger. The exact steps for that is outside the scope of this post but generally, you’ll want to activate the new version of Ruby with:
# rvm use 1.8.7
then install the passenger gem with:
# rvm gem install passenger
then install mod_passenger:
# passenger-install-apache2-module -a && passenger-install-apache2-module --snippet > /etc/httpd/conf.d/mod_passenger.conf
5) And we’re done! Apache is set up to use Ruby 1.8.7 + the newest version of mod_passenger:
# ruby -v<br /> ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]<br /> # rvm gem list --local | grep passenger<br /> passenger (3.0.7)Posted in: Apache