Installing RVM and Ruby on CentOS 7

     

The @base Ruby version is ancient and actually EOL’d, so you should really use RVM for your Ruby needs. The good news is that it’s really simple.

Table of Contents

Cleanup

Chances are, you already have Ruby installed from the EL repo. And possibly some gems, too. In this case:

# remove old versions
gem cleanup
# remove gems that came via `gem install`
for x in $(gem list | cut -f 1 -d ' '); do gem uninstall $x -x -I -a; done
# remove packaged gems and all of ruby
yum erase ruby*

Install

RVM

Before you can obtain up-to-date Ruby, you need RVM. So let’s get that.

# import the necessary GPG keys
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# install RVM
curl -L get.rvm.io | bash -s stable
# spare the logout/login
source /etc/profile.d/rvm.sh

Ruby

Now we have the tools, install Ruby itself. Pick the Ruby version needed for your application, then (in this example I use 2.5):

export RUBY_VER='2.5'
rvm install ${RUBY_VER}
rvm use ${RUBY_VER} --default

Easy as pie.

Upgrade

RVM

rvm get stable
rvm reload

Ruby

Query the list of available versions:

rvm list known

Install a branch with:

export RUBY_VER='2.6'
rvm install ${RUBY_VER}
rvm use ${RUBY_VER} --default
rvm cleanup all

If you no longer need the old version:

rvm remove 2.5