Ruby on Rails: The 3, 2 and 1 ways to install the framework on Linux

Ruby on Rails is a free framework written in Ruby with the MVC design model: Model – View – Controller. Also called RoR or simply Rails, the first version of the framework was released in 2004 written by David Heinemeier Hansson.

Ruby on Rails conventions :

  • Don’t repeat yourself : you are invited not to repeat your code using various techniques.
  • Convention rather than configuration : specify configuration items only if they do not comply with established conventions. Rails exploits this by offering default behaviors for most of its features.
3 2 1 Here we go !
3, 2, 1 Here we go !

3 ways to install Ruby on Linux

First method: Install Ruby from the Ubuntu repositories

You can install Ruby on your system through the APT package manager. This method is quite simple. This way, you will have the latest stable version.

Update your package manager and install Ruby

 $ sudo apt update && sudo apt install ruby-full

To check that your installation has been successfully completed, check the Ruby version

 $ ruby --version

Second method: Install Ruby using Rbenv

Rbenv is the tool that will give you more flexibility by allowing you to change Ruby versions easily.

Update your package manager and install the required packages for ruby-build

$ sudo apt update && sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

Use the curl data transfer tool to install rbenv and ruby-build

 $ curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

Add $HOME/.rbenv/bin to the environment variable of your PATH system

If you use Bash :

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ source ~/.bashrc 

If you use ZSH :

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
$ source ~/.zshrc 

Finally, install the latest version of Ruby and set the default version :

To know the latest stable version of Ruby on Rvm and Rbenv click HERE

$ rbenv install 2.5.1
$ rbenv global 2.5.1 

You can list all the versions of Ruby available using the command :

rbenv install -l

To check the version of Ruby : ruby -v

Third method: install Ruby with RVM

RVM is a tool that, like the previous one, provides flexibility to manage multiple Ruby environments

Update your package manager and install the packages required for RVM and Ruby installation

$ sudo apt update && sudo apt install udo apt install curl g++, gcc, autoconf, automake, bison, libc6-dev, libffi-dev, libgdbm-dev, libncurses5-dev, libsqlite3-dev, libtool, libyaml-dev, make, pkg-config, sqlite3, zlib1g-dev, libgmp-dev, libreadline-dev, libssl-dev 

Install RVM

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB && curl -sSL https://get.rvm.io | bash -s stable 

To use RVM without wasting time, enter the following command :

source ~/.rvm/scripts/rvm

Finally, install the latest stable version of Ruby

$ rvm install 2.5.1
$ rvm use 2.5.1 --default 

For more information on RVM, click HERE

2 ways to install PostgreSQL for your database

First method: Install the package from the command line

Simply install the PostgreSQL package

$ sudo apt update && sudo apt install postgresql 

Second method: Install PostgreSQL manually via the EnterpriseDB interactive installer

To download the desired version, click HERE

Make your downloaded version executable

$ sudo chmod +x postgresql-10.6-1-linux-x64.run 

Enfin, exécutez-le pour procéder à son installation

$ sudo ./postgresql-10.6-1-linux-x64.run 

By default, only the Postgres user can connect to the database. You must log in at least once with the Postgres user to be able to do the operations on your database with Ruby on Rails

$ sudo -i -u postgres
Password:

1 way to install the latest version of Rails

To know the latest version of Rails, click HERE and to see the sources, click HERE

To install it, nothing could be easier, enter the following command :

$ gem install rails 

Comment on the method you prefer or have used 😉

signature Pierre-Christophe

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.