RVM is a great piece of software. Without it, it’d be a nightmare to maintain multiple versions of Ruby and multiple gemsets. I know that I use it every day, and if you’re developing with Ruby, you’ll probably want to use it as well.
This week, I’ll be showing you how to install RVM on CentOS 5, as well as some quick tips about using RVM to make your life easier. The format will be a bit different this week; I’m going to walk you through everything I did and talk about each snag and how to get around it.
But first, some notes:
- If you’re blindly cutting and pasting the commands here without understanding them, it’s very likely that you’ll end up with a mess.
- These instructions won’t get you a working install of Rails that you can use with InterWorx-CP. Instead, please see http://www.interworx.com/support/docs/siteworx/rails for help setting up Rails with InterWorx-CP.
- While the instructions provided are working for the author, we can’t promise that they’ll work for you. If you’re having trouble getting something working, please leave a comment and we’ll try to help.
- Following this guide is done at your own risk and it’s very possible that you’ll break something that we won’t be able to fix for you. If you’re unsure about something and you’re a current client, please contact us at email@example.com with any questions, and mention this article if this is what you’re working on. If you’re not currently a client, leave a comment and we’ll try to help.
- Pay attention to the 32-and-64-bit-specific stuff here. I’ll try to note where it’s applicable, but again you’ll need to be cautious working your way through this tutorial.
I’d like to thank the contributors to the following for making this tutorial possible:
- IUS Repos, for the autoconf RPMs
- E[xtra]P[ackages for]E[nterprise]L[inux], for the scons RPMs
- Daniel Kehoe & others, for the great Rails 3.1 installation guide
- Wayne E. Seguin, for RVM
If you’re here, I’m assuming that you tried just going to the RVM installation page and didn’t have much luck. Here is the error I get on CentOS 5.6 when I try to run the normal RVM installer:
<br /> $ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)<br /> Cloning into rvm...<br /> github.com[0: 126.96.36.199]: errno=Connection timed out<br /> fatal: unable to connect a socket (Connection timed out)<br /> Cloning into rvm...<br /> error: SSL certificate problem, verify that the CA cert is OK. Details:<br /> error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com/wayneeseguin/rvm.git/info/refs</p> <p>fatal: HTTP request failed</p> <p>ERROR: Unable to clone the RVM repository, attempted both git:// and https://<br />
(if you’re seeing something else, you probably need to install one of the following: git >= v1.7, curl, bash >= v3.2, patch, bison, autoconf)
So first off, we’re going to need to disable git’s SSL certificate verification, like this:
<br /> export GIT_SSL_NO_VERIFY=true<br />
Once that’s all set, we’ll need to add the RVM loader to our ~/.bash_profile, but first we need to open it up and make sure that ‘break’ doesn’t appear in ~/.bash_profile. If it does, you’ll probably want to re-write whatever is in there that requires ‘break’ so that it doesn’t require ‘break’ anymore. Otherwise, RVM will not likely function properly. If you need help with this, jump on Freenode IRC and ask around in #bash or #ruby and one of the great people there should be able to help you get your config straightened out.
After your ~/.bash_profile is set up properly, exit your shell session and start a new one. You should now try running this:
<br /> $ type rvm |head -1<br /> rvm is a function<br />
and make sure that it says ‘rvm is a function’ like mine did above. If not, go back and look in your ~/.bash_profile and ~/.bashrc and anything else that gets chainloaded automatically with a new shell session and see if ‘break’ is in there anywhere, which is likely the cause of your problems. Again here, Freenode IRC is your friend (ask in #bash or #ruby).
Now that we have RVM working, it’s time to install some rubies! Let’s start with 1.8.7, because it’s pretty popular and odds are that something you’ll want to use depends on it:
<br /> $ rvm list known_strings<br />
That will get you a list of all the versions of ruby that RVM can install for you. Let’s install ‘ruby-1.8.7-p352’. But first, we need to use ‘yum’ to install ‘bison’.
<br /> yum -y install bison<br /> $ rvm install ruby-1.8.7-p352<br />
Uhh ooh. It looks like we’re getting the SSL certificate verification failure again. Let’s just add that git env var into our .bash_profile, load it up again, and try using RVM to install 1.8.7 again (this will take a few minutes to complete):
<br /> $ echo 'export GIT_SSL_NO_VERIFY=true' >> ~/.bash_profile<br /> $ source ~/.bash_profile<br /> $ rvm install ruby-1.8.7-p352<br />
It looks like it failed again, this time due to autoconf missing. And ooh dear, it looks like the RHEL version we have installed is too out of date to be used with RVM here. Let’s proceed with extreme caution.
First, we’re going to back up a list of all our RPMs just in case everything goes south. We’re going to open it up in less and look for ‘autoconf’ to get the exact name we’ll need to uninstall it (tip: use ‘/’ to search in less).
<br /> $ rpm -qa > rpmlist<br /> $ less rpmlist<br />
The system I’m on had ‘autoconf-2.59-12’, so let’s remove that without removing any of the dependencies:
<br /> $ rpm -e --nodeps autoconf-2.59-12<br />
And now the fun part: download, extract, configure, make, install, and symlink the new autoconf to where CentOS expects it:
<br /> $ wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.63.tar.gz<br /> $ tar -xvvzf autoconf-2.63.tar.gz<br /> $ cd autoconf-2.63<br /> $ ./configure<br /> $ make -j4<br /> $ make install<br /> $ ln -s /usr/local/bin/autoconf /usr/bin/autoconf<br /> $ autoconf --version<br />
Once that’s all done, we should be able to finally install Ruby inside RVM. Let’s just type the shorthand this time:
<br /> $ rvm install 1.8.7<br />
It worked! But let us not sit idly marveling at our greatness. Let’s update RVM, then install 1.9.2 and ruby-head, as well as a Rails 3.1 setup!
We’ll need to make sure that /tmp is mounted with exec rights, so let’s go ahead and re-mount that, update RVM, and reload it:
<br /> $ mount -o remount,rw,exec,nosuid,nodev,noatime,usrquota,grpquota /tmp # make sure to re-mount this with noexec when you are done!<br /> $ rvm get head<br /> $ rvm reload<br />
Now it’s time to install whatever versions of ruby you need:
<br /> $ rvm install 1.9.2<br /> $ rvm install ruby-head<br />
Next, we’re going to need to update RubyGems to support Rails 3.1. It also needs Ruby >= 1.9.2, so let’s use that 1.9.2 install we just hooked up. We’re going to also set Ruby 1.9.2 to be our default ruby, then make a new gemset just for Rails 3.1 and set that as the default:
<br /> $ rvm --default use 1.9.2<br /> $ ruby -v<br /> $ gem update --system<br /> $ rvm 1.9.2@rails31 --create --default<br />
We also need to update rake to at least 0.9.2 before we continue:
<br /> $ gem update rake<br /> $ rake --version<br />
Finally, we can give the Rails 3.1 install a shot:
<br /> $ gem install rails --pre<br />
We should now be able to create a Rails 3.1 app, like this:
<br /> $ rails new testapp<br /> $ cd $_<br /> $ bundle install<br />
This failed for me due to my sqlite installation being really old. Let’s fix that the same way we fixed autoconf:
<br /> $ rpm -qa > rpmlist<br /> $ less rpmlist<br /> $ rpm -e --nodeps sqlite-3.3.6-5 sqlite-devel-3.3.6-5<br /> $ wget http://www.sqlite.org/sqlite-autoconf-3070701.tar.gz<br /> $ tar -xvvzf sqlite-autoconf-3070701.tar.gz<br /> $ cd sqlite-autoconf-3070701<br /> $ ./configure<br /> $ make -j4<br /> $ make install<br /> $ ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3<br /> $ cp -R /usr/local/lib/* /usr/lib64/ # copy all the new sqlite libs to the right place<br /> $ sqlite3 -version<br />
<br /> $ rails new testapp2<br /> $ cd $_<br /> $ bundle install<br />
<br /> $ # 64-bit: rpm -i http://download.fedora.redhat.com/pub/epel/5/x86_64/scons-1.2.0-3.el5.noarch.rpm<br /> $ # 32 bit: rpm -i http://download.fedora.redhat.com/pub/epel/5/i386/scons-1.2.0-3.el5.noarch.rpm<br /> $ yum install gcc-c++ mhash mhash-devel<br /> $ gem install mustang<br />
If mustang compiles OK (it takes a few minutes), you should be golden. However, we need to add the ‘mustang’ gem to our Gemfile and re-run ‘bundle install’ to get WEBrick working. Here is where I put the necessary line, “gem ‘mustang'”, in my Gemfile:
<br /> source 'http://rubygems.org'</p> <p>gem 'rails', '3.1.0.rc6'</p> <p># Bundle edge Rails instead:<br /> # gem 'rails', :git => 'git://github.com/rails/rails.git'</p> <p>gem 'sqlite3'<br /> gem 'mustang'<br />
Now, make sure you’re inside your project folder for your Rails 3.1 app and re-run ‘bundle install’:
<br /> $ bundle install<br />
We should be all set, and
<br /> rails s; echo "BOOM!"<br />
should pop open WEBrick with your working Rails 3.1 app. Enjoy! Ooh, and don’t forget to re-mount ‘/tmp’ with the ‘noexec’ flag. ‘mount -a’ should do it for you, but please verify!
For extra credit, open your Gemfile back up and uncomment the “gem ‘unicorn'” line. Re-run ‘bundle install’ and set up something like nginx to proxy requests to unicorn serving your rails app.Posted in: Linux