Vendredi 23 novembre 2018

How To Install Ruby on Ubuntu, Debian and LinuxMint using RVM

How To Install Ruby on Ubuntu, Debian and LinuxMint using RVM

Ruby is popular programming language among a large number of developers. Rails are the framework to run ruby language. Ruby language was created by Yukihiro “Matz” Matsumoto and first published in 1995. This article will help you to install ruby on rails on Ubuntu, Debian and Linuxmint operating systems using RVM. RVM is the Ruby Version Manager helps for installing and managing Ruby language on systems.

Step 1 – Install RVM

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

apt-get install curl

Install RVM

Before installing RVM first we need to import public key in our system then use curl to install rvm in our system.

curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -
curl -sSL https://get.rvm.io | sudo bash -s stable

After installing RVM first we need to set up rvm environment using below command. so that current shell takes new environment settings.

source /etc/profile.d/rvm.sh

Add user to rvm group

sudo usermod -a -G rvm $USER

Install Ruby Dependencies

Install all the dependencies for installing Ruby automatically on the system. Run below command on terminal.

rvm requirements

Step 2 – List Available Ruby Versions

Get a list of available versions of Ruby language. You can install any version of your choice or requirements showing on the list.

rvm list known | grep "\[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[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]

Step 3 – Install Ruby Version

RVM is useful for installation of multiple Ruby versions on the single system. Use the following command to install required Ruby on your system. As shown below example will install Ruby 2.4.1 on your system.

rvm install 2.4.1
Searching for binary rubies, this might take some time.
No binary rubies available for: debian/8/x86_64/ruby-2.4.1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for debian.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.4.1, this may take a while depending on your cpu(s)...
ruby-2.4.1 - #downloading ruby-2.4.1, 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 11.9M  100 11.9M    0     0  11.4M      0  0:00:01  0:00:01 --:--:-- 11.4M
ruby-2.4.1 - #extracting ruby-2.4.1 to /usr/local/rvm/src/ruby-2.4.1....
ruby-2.4.1 - #applying patch /usr/local/rvm/patches/ruby/2.4.1/random_c_using_NR_prefix.patch.
ruby-2.4.1 - #configuring..................................................................
ruby-2.4.1 - #post-configuration..
ruby-2.4.1 - #compiling................................................................................
ruby-2.4.1 - #installing...........
ruby-2.4.1 - #making binaries executable..
ruby-2.4.1 - #downloading rubygems-2.6.14
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  751k  100  751k    0     0  5683k      0 --:--:-- --:--:-- --:--:-- 5692k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.1 - #extracting rubygems-2.6.14....
ruby-2.4.1 - #removing old rubygems.........
ruby-2.4.1 - #installing rubygems-2.6.14...........................
ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1@global
ruby-2.4.1 - #importing gemset /usr/local/rvm/gemsets/global.gems...............................................
ruby-2.4.1 - #generating global wrappers........
ruby-2.4.1 - #gemset created /usr/local/rvm/gems/ruby-2.4.1
ruby-2.4.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.1 - #generating default wrappers........
ruby-2.4.1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.1 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

Step 4 – Setup Default Ruby Version

Use rvm command to set up default ruby version to be used by applications. You can install multiple versions as defined in above step. Now select which version you want to use.

rvm use 2.4.1 --default
  Using /usr/local/rvm/gems/ruby-2.4.1

Step 5 – Check Ruby Version

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

ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]