How to install Ruby & Rails on Ubuntu

June 4, 2016 14 Yehor Rykhnov

Example of installation Ruby & Rails on OS Ubuntu 14.04

We need to install Ruby on Ubuntu, it means we will install it.

Installing Ruby through rbenv, variant 1

This variant describes the Ruby installation via rbenv

cd ~
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

Install the package management manager:

gem install bundler

After the installation or change version of Ruby and also when change gem you need run rehash:

rbenv rehash

Installing Ruby through RVM, variant 2

This variant describes the installation of Ruby through RVM

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v

Install the package management manager:

gem install bundler

Installing Rails

Since Rails comes with a large number of dependencies, we need to set Javascript runtime environment such as NodeJS, Installing Node.js and NPM in Ubuntu

Installing Rails:

gem install rails -v 4.2.6

If you are using rbenv, you need to run the following command to make available Rails:

rbenv rehash

To check whether you are correctly done everything, you need to run the rails -v:

rails -v
# Rails 4.2.6

That's all