Recently, I found myself stuck for installing the ruby Gem falkorlib on a CentOS 7 machine which feature by default only an old version of Ruby (i.e. 2.0).

If you want to install a more recent version of Ruby, you have mainly three options:

  1. Install a built RPM (using rpmbuild) from ruby sources and a specific .spec file
  2. Rely on the CentOS Software Collections (SCL).
  3. Rely on RVM

Build and Install from Ruby sources

1
2
3
4
5
6
# Install development packages and dependencies
yum -y groupinstall "Development Tools"
yum --enablerepo=epel -y install  gdbm-devel libyaml-devel
#
# Prepare the RPM directory layout
mkdir -p /root/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}

Then you will need to download Ruby source matching the spec files we are going to use, i.e.

Of course, you should be able to easily adapt these files to match your own wished version Then you can build the RPM from it and install it.

1
2
3
4
5
6
7
8
9
### Exemple for version 2.3.8
# Download sources
wget https://cache.ruby-lang.org/pub/ruby/ruby-2.3.8.tar.gz  -P /root/rpmbuild/SOURCES
# Download the spec file
wget https://raw.githubusercontent.com/feedforce/ruby-rpm/master/ruby-2.3.spec -P /root/rpmbuild/SPECS --no-check-certificate
# Build the RPM
rpmbuild -bb /root/rpmbuild/SPECS/ruby-2.3.spec
# ... and install it
ls --color=never /root/rpmbuild/RPMS/x86_64/ruby-2.3.8*.rpm |  xargs yum -y localinstall