We will install different Ruby releases using Ruby Version Manager.

RVM installation

Download GPG key :

[root@ruby ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Then, download and install RVM :

[root@ruby ~]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.27.0.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc
gpg: Signature made Tue 29 Mar 2016 03:49:47 PM CEST using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
     Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.27.0.tgz'
Creating group 'rvm'

Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# Administrator,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: https://rvm.io/help and https://twitter.com/rvm_io

Create “rvm” user :

[root@ruby ~]# useradd rvm -g rvm

Set password :

[root@ruby ~]# echo "rvm:my_password" | chpasswd

Substitue user to “rvm” :

[root@ruby ~]# su - rvm

And add following lines in “.bashrc” :

[rvm@ruby ~]$ tail -2 .bashrc
umask u=rwx,g=rwx,o=rx
source /etc/profile.d/rvm.sh

Exit and logon “rvm” again to validate changes :

[rvm@ruby ~]$ exit
logout
[root@ruby ~]# su - rvm

What releases can I install ?

[rvm@ruby ~]$ rvm list known rubies | egrep "^\[ruby"
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-head

Ruby 2.3.3 installation using RVM

Try to install it :

[rvm@ruby ~]$ rvm install 2.3.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-2.3.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: patch, libyaml-devel, glibc-headers, autoconf, gcc-c++, glibc-devel, patch, readline-devel, zlib-devel, libffi-devel, openssl-devel, bzip2, automake, libtool, bison, sqlite-devel...rvm password required for 'yum install -y patch libyaml-devel glibc-headers autoconf gcc-c++ glibc-devel patch readline-devel zlib-devel libffi-devel openssl-devel bzip2 automake libtool bison sqlite-devel':

OK, binary Ruby 2.3.3 doesn’t exist for CentOS 7.2 distribution, we need to compile it, and to do that, many RPMs need to be installed first…

Install required packages :

  • Logged as root :
[rvm@ruby ~]$ exit
  • Install missing RPMs :
[root@ruby ~]# yum install -y patch libyaml-devel glibc-headers autoconf gcc-c++ glibc-devel patch readline-devel zlib-devel libffi-devel openssl-devel bzip2 automake libtool bison sqlite-devel

Retry Ruby 2.3.3 installation :

  • As rvm :
[root@ruby ~]# su - rvm
  • Retry the installation :
[rvm@ruby ~]$ rvm install 2.3.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-2.3.3.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.3.3, this may take a while depending on your cpu(s)...
ruby-2.3.3 - #downloading ruby-2.3.3, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.7M  100 13.7M    0     0   683k      0  0:00:20  0:00:20 --:--:--  718k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.3.3 - #extracting ruby-2.3.3 to /usr/local/rvm/src/ruby-2.3.3....
ruby-2.3.3 - #configuring..........................................................
ruby-2.3.3 - #post-configuration..
ruby-2.3.3 - #compiling.................................................................................
ruby-2.3.3 - #installing.............................
ruby-2.3.3 - #making binaries executable..
Installed rubygems 2.5.2 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.3.3 - #gemset created /usr/local/rvm/gems/ruby-2.3.3@global
ruby-2.3.3 - #importing gemset /usr/local/rvm/gemsets/global.gems...............................................
ruby-2.3.3 - #generating global wrappers........
ruby-2.3.3 - #gemset created /usr/local/rvm/gems/ruby-2.3.3
ruby-2.3.3 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.3 - #generating default wrappers........
ruby-2.3.3 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.3.3 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
  • Generate documentation :
[rvm@ruby ~]$ rvm docs generate-ri

OK, Ruby 2.3.3 is now installed :

[rvm@ruby ~]$ rvm list

rvm rubies

=* ruby-2.3.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Install Ruby 1.9.3 legacy release :

[rvm@ruby ~]$ rvm install 1.9.3

And Ruby 2.0 as well :

[rvm@ruby ~]$ rvm install 2.0

So, currently, we have :

[rvm@ruby ~]$ rvm list

rvm rubies

   ruby-1.9.3-p551 [ x86_64 ]
=> ruby-2.0.0-p648 [ x86_64 ]
 * ruby-2.3.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

Release 2.0 by default :

[rvm@ruby ~]$ ruby --version
ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux]

Remove oldest (1.9.3) version :

[rvm@ruby ~]$ rvm remove 1.9.3

Which Ruby version I’m using ?

Create this very short script :

[rvm@ruby ~]$ cat display_version.rb
#!/bin/env ruby

puts "We are running Ruby release "+RUBY_VERSION

Execute this script :

[rvm@ruby ~]$ chmod u+x display_version.rb
[rvm@ruby ~]$ ./display_version.rb
We are running Ruby release 2.3.3

Switch to Ruby 2.0.0 :

[rvm@ruby ~]$ rvm use 2.0.0
Using /usr/local/rvm/gems/ruby-2.0.0-p648

Default Ruby release is “2.0.0” from now :

[rvm@ruby ~]$ rvm list

rvm rubies

=> ruby-2.0.0-p648 [ x86_64 ]
 * ruby-2.3.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

And now, execute this script again :

[rvm@ruby ~]$ ./display_version.rb
We are running Ruby release 2.0.0

This RVM, we can easily install and switch several Ruby releases.

 

PDF24    Send article as PDF   

Leave a Reply

Your email address will not be published. Required fields are marked *


*