Warning – Ruby 1.9 is reached to end of life and no more maintained. Kindly use below tutorials to install latest version of ruby
Advertisement

Ruby programming language is becoming is more popular these days. Ruby language was created by Yukihiro “Matz” Matsumoto and first published in 1995. This article will help you to install Ruby language in CentOS, RedHat system using RVM. For this article I am using CentOS 6.5. RVM provides easy set of commands to install single or multiple versions of Ruby on single server.

Step 1: Upgrade Packages

It is the best practice to keep your system up to date with latest packages. Before running below command make sure that update will not affect to your running apps ( if any )on server else skip it

# yum update

Step 2: Installing Recommended Packages

There are few developemnt libraries required to run Ruby on Linux. Use following command to install recommended packages on your server using yum.

# yum install gcc-c++ patch readline readline-devel zlib zlib-devel
# yum install libyaml-devel libffi-devel openssl-devel make
# yum install bzip2 autoconf automake libtool bison iconv-devel

Step 3: Install RVM ( Ruby Version Manager )

Install latest stable version of RVM on your system using following command. This command will automatically download all required files and install on your system.

# curl -L get.rvm.io | bash -s stable

[Sample Output]

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20511  100 20511    0     0   1120      0  0:00:18  0:00:18 --:--:-- 19722
Downloading https://github.com/wayneeseguin/rvm/archive/stable.tar.gz
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: http://rvm.io/help and https://twitter.com/rvm_io

Step 4: Setup RVM Environment

After installing RVM first we need to setup rvm environment using below command.

# source /etc/profile.d/rvm.sh

Step 5: Install Required Ruby Version

RVM provides option to manage multiple ruby version on single system. Use following command to install required version of Ruby.

# rvm install 1.9.3

[Sample Output]

Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/i386/ruby-1.9.3-p545.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Updating system......
Installing required packages: libyaml-devel......
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.3-p545, this may take a while depending on your cpu(s)...
ruby-1.9.3-p545 - #downloading ruby-1.9.3-p545, 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 9802k  100 9802k    0     0   217k      0  0:00:45  0:00:45 --:--:--  393k
ruby-1.9.3-p545 - #extracting ruby-1.9.3-p545 to /usr/local/rvm/src/ruby-1.9.3-p545.
ruby-1.9.3-p545 - #applying patch /usr/local/rvm/patches/ruby/GH-488.patch.
ruby-1.9.3-p545 - #applying patch /usr/local/rvm/patches/ruby/ssl_no_ec2m.patch.
ruby-1.9.3-p545 - #configuring..............................................
ruby-1.9.3-p545 - #post-configuration.
ruby-1.9.3-p545 - #compiling...................................................................
ruby-1.9.3-p545 - #installing........................
ruby-1.9.3-p545 - #making binaries executable.
ruby-1.9.3-p545 - #downloading rubygems-2.2.2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  404k  100  404k    0     0  25393      0  0:00:16  0:00:16 --:--:--  335k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-1.9.3-p545 - #extracting rubygems-2.2.2.
ruby-1.9.3-p545 - #removing old rubygems.
ruby-1.9.3-p545 - #installing rubygems-2.2.2...............
ruby-1.9.3-p545 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p545@global
ruby-1.9.3-p545 - #importing gemset /usr/local/rvm/gemsets/global.gems.....
ruby-1.9.3-p545 - #generating global wrappers.
ruby-1.9.3-p545 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p545
ruby-1.9.3-p545 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p545 - #generating default wrappers.
ruby-1.9.3-p545 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p545 - #complete
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

    http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering

Please consider upgrading to ruby-2.1.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

Step 6: Install Another Version ( if Required )

If you want using multiple versions of ruby, you can install it also using rvm else skip this step.

# rvm install 1.8.6

Step 7: Setup Default Ruby Version

Use rvm command to setup default ruby version to be used by applications.

# rvm use 1.9.3 --default 

Using /usr/local/rvm/gems/ruby-1.9.3-p545
Step 8: Check Current Ruby Version

Using following command you can check the current ruby version is used.

# ruby --version

ruby 1.9.3p545 (2014-02-24 revision 45159) [i686-linux]

I hope above steps will help you for installing multiple Ruby version using RVM.

Share.

20 Comments

  1. hi rahul i am beginer in ruby in rail i am using ubuntu
    in my system when i am using check ersion of ruby using
    —> sudo ruby -v
    so it return “ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]”
    without sudo i write —> ruby -v
    so it return “ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-linux]”
    when i am set default version of ruby in rvm using –> rvm 2.0.0 use –default
    so it display ruby version in ruby 2.0.0p598
    when i install rails urin gem without sudo —> gem install rails
    so it return
    ERROR: While executing gem … (Errno::EACCES)
    Permission denied – /home/keyur/.gem/specs
    while i am using sudo —>sudo gem install rails
    it return
    ERROR: Error installing rails:
    activesupport requires Ruby version >= 1.9.3.
    i try also chnage version of ruby usinfg —> rvm 1.9.3 use –default
    after that when i check version without sudo like —>ruby -v
    so it return
    ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
    but still it return following error
    ERROR: Error installing rails:
    activesupport requires Ruby version >= 1.9.3.
    pls help how i can solve this error,
    Thanks in advance!!!

  2. Alberto Ghirotti on

    Thanks for this nice article, I noted that all the commands you give are performed as root user (#), in my case all worked perfectly installing 1.9.3 into a Oracle Linux 6.5 Virtual Box Machine, but the last command (ruby –version) given from a oracle user shell (not by root) gave me 1.8.7, because /usr/bin/ruby was still the previous version.
    To enhance your answer I would add the following final steps:
    – remove previous ruby versions (#yum remove ruby); after this ruby — version from a non root terminal should give error because ruby has been removed

    – all your steps you described

    – find the path of the new (1.9.3) ruby version: /usr/local/rvm/gems/ruby-1.9.3-p547/wrappers/ruby
    – from root prompt: #ln -s /usr/local/rvm/gems/ruby-1.9.3-p547/wrappers/ruby /usr/bin/ruby
    – after this open a new oracle terminal and $ruby –version should give 1.9.3

    Again thank you for your work
    Alberto

  3. I hope the below config is correct.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [root@kodiak-SA2 rearview-1.2.0]# gem environment
    RubyGems Environment:
    – RUBYGEMS VERSION: 2.2.2
    – RUBY VERSION: 1.9.3 (2014-02-24 patchlevel 545) [x86_64-linux]
    – INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p545
    – RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.3-p545/bin/ruby
    – EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p545/bin
    – SPEC CACHE DIRECTORY: /root/.gem/specs
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86_64-linux
    – GEM PATHS:
    – /usr/local/rvm/gems/ruby-1.9.3-p545
    – /usr/local/rvm/gems/ruby-1.9.3-p545@global
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => true
    – :backtrace => false
    – :bulk_threshold => 1000
    – REMOTE SOURCES:
    https://rubygems.org/
    – SHELL PATH:
    – /usr/local/rvm/gems/ruby-1.9.3-p545/bin
    – /usr/local/rvm/gems/ruby-1.9.3-p545@global/bin
    – /usr/local/rvm/rubies/ruby-1.9.3-p545/bin
    – /usr/local/rvm/bin
    – /root/jruby-1.7.12/bin
    – /usr/lib64/qt-3.3/bin
    – /usr/local/sbin
    – /usr/local/bin
    – /sbin
    – /bin
    – /usr/sbin
    – /usr/bin
    – /root/bin
    – /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  4. shyam krishna khadka on

    I have problem with installation , when I run yum install gcc-c++ patch readline readline-devel zlib zlib-devel command, I got errors as
    Trying other mirror.
    : [Errno 14] PYCURL ERROR 22 – “The requested URL returned error: 404”
    Trying other mirror.

    My repos infos are as below :
    ls -l /etc/yum.repos.d/
    total 28
    -rw-r–r–. 1 root root 1926 Jun 26 2012 CentOS-Base.repo
    -rw-r–r–. 1 root root 637 Jun 26 2012 CentOS-Debuginfo.repo
    -rw-r–r–. 1 root root 626 Jun 26 2012 CentOS-Media.repo
    -rw-r–r–. 1 root root 2593 Jun 26 2012 CentOS-Vault.repo
    -rw-r–r– 1 root root 957 Apr 18 16:23 epel.repo
    -rw-r–r– 1 root root 1056 Nov 5 2012 epel-testing.repo
    -rw-r–r– 1 root root 332 Jul 20 2011 rbel6.repo

    My centos version is as
    #cat /etc/issue
    CentOS release 6.3 (Final)
    Kernel r on an m

    Please help me.

  5. Hi,

    Thanks for the low down.

    I have followed your steps and enabled 1.9.3 with RVM but I can’t see it operating systemwide. When I log in to the server (as a regular user) I still see ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

    Can you make any suggestions.

    Thanks,
    Ian

      • Hi Roopashree,

        I assume you must have executed following command to make 1.9.3 as default .

        # rvm use 1.9.3 –default

        Can you check version immediate after running above command

        # ruby –version

  6. Nice article , thanks , all the required info in one place. Btw have you tried to install gem “capybara-webkit”, does it install without any objection ?

    Thanks again for the article.

    • Hi Shahbaz,

      In order to install capybara-webkit, You need to set QMAKE environment variable.
      Install qt47-webkit-devel rpm and set QMAKE using below command.
      export QMAKE=/usr/bin/qmake-qt47

      Hope it will help you… If you still face issue, let me know what OS and version are you using…

      • Hi,
        Ah!!! Finally solved it, cause I was installing on CentOS 5.8, and after installing qt47 when its time to install caypybara-webkit, it will look for qt47 on usr/lib/bin , but qt47 resides on usr/lib64/bin. If ‘export PATH’ doesn’t work on 5.8 then just create a symlink to lib64.
        Thanks again for all the help.
        Cheers.

Exit mobile version