CentOS + RVM
Problem: You would like to run multiple versions of ruby
Solution: Use Ruby Version Manager (RVM) to install and manage multiple ruby versions without clobbering the system version of ruby.
Prerequisites
- git
- autoconf
- automake
- libtool
- readline and readline-devel
Step 1: Install prerequisites
Install git
CentOS 6.x
In CentOS 6, git is included in the base repository so it can be installed with “yum install git”. Note that on a cPanel server this command will likely fail due to the fact that cPanel has modified the yum configuration file (/etc/yum.conf) to exclude some packages; in this case some perl packages. Therefore, you must explicitly disable the excludes from /etc/yum.conf with the “disableexcludes” option. Thus, the command becomes:
1 |
yum install git --disableexcludes=main |
CentOS 5.x
In CentOS 5, you can install git from a non-standard repository or install from source. I chose to install from the epel repository. Caution if you are running a cPanel server! The use of third-party repositories such as epel can create package conflicts and potentially interfere with cPanel. The epel repository can be added to your list of yum repos by installing the rpm from fedora.org. At the time of writing, the base directory for CentOS 5 was located at http://dl.fedoraproject.org/pub/epel/5/. Be sure to choose the subdirectory that corresponds to the architecture of your server. For example, to install the rpm for 64-bit systems you would run the following command:
1 |
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm |
Once you have added the epel repository, you will be able to install git with the following command:
1 |
yum install git-core --disableexcludes=main |
Note the “disableexcludes” option. See the related notes under the CentOS 6.x heading above for an explanation as to why this is necessary.
(CentOS 5.x only) Reinstall autoconf, automake, and libtool
The package autoconf and its dependencies automake and libtool must be uninstalled and then reinstalled from source because git requires autoconf 2.6+ while CentOS 5.x packages autoconf 2.59.
Install readline and readline-devel
Readline and its development libraries are packages that can be installed with yum. These are required for building certain ruby binaries such as Ruby Enterprise Edition. The following command will install both of these packages:
1 |
yum install readline-devel readline |
Uninstall autoconf, automake and libtool
Remove these three packages with yum like so:
1 |
yum remove autoconf automake libtool |
Reinstall autoconf from source
1 2 3 4 5 6 7 |
cd /usr/local/src wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.63.tar.gz tar -xf autoconf-2.63.tar.gz cd autoconf-2.63 ./configure --prefix=/usr/local make make install |
Reinstall automake from source
1 2 3 4 5 6 7 |
cd /usr/local/src wget http://ftp.gnu.org/gnu/automake/automake-1.11.tar.gz tar -xf automake-1.11.tar.gz cd automake-1.11 ./configure --prefix=/usr/local make make install |
Reinstall libtool from source
1 2 3 4 5 6 7 |
cd /usr/local/src wget http://mirrors.ibiblio.org/pub/mirrors/gnu/ftp/gnu/libtool/libtool-1.5.8.tar.gz tar -xf libtool-1.5.8.tar.gz cd libtool-1.5.8 ./configure --prefix=/usr/local make make install |
Step 2: Install rvm (server-wide)
Reference: https://rvm.io/rvm/install/
Important: The following instructions will install rvm server-wide. All commands must be run as root. Additionally, it is required that you include “sudo” as it appears in the following command to ensure that rvm is properly installed. Even if you are logged in as root, omitting “sudo” will cause rvm to install incorrectly (it will actually install just for the root user and rvm will end up getting installed into /root/.rvm instead of /usr/local/rvm).
Run the following command as root to install rvm globally:
1 |
\curl -L https://get.rvm.io | sudo bash -s stable --ruby |
If you run into any certificate errors when attempting to run the installation script, you will need to configure curl to ignore certificate warnings. I achieved this by running the following command…
1 |
echo insecure >> ~/.curlrc |
…and then retrying the installation:
1 |
\curl -L https://get.rvm.io | sudo bash -s stable --ruby |
Step 3: Install a ruby
To install a version of Ruby, you use “rvm install RUBY_NAME”. For example, to install ruby 1.9.3 with patch level 194, you would run:
1 |
rvm install ruby-1.9.3-p194 |
Rubies installed by rvm can be found under the following directory:
1 |
/usr/local/rvm/gems |
More information about installing rubies can be found in the official documentation:
https://rvm.io/rvm/install/
Tips
The following commands demonstrate some common commands that you will want to know:
View a list of available rubies
1 |
rvm list |
Install a ruby
1 |
rvm install RUBY_NAME |
Switch back to using the system’s version of ruby
1 |
rvm use system |
Use a specific version of ruby installed by rvm
1 |
rvm use RUBY_NAME |
Set default ruby
1 |
rvm alias create default RUBY_NAME |
Update rvm
1 |
rvm get stable |
…or, for the bleeding edge version…
1 |
rvm get latest |