How to install Ruby 2.4 with RVM, Rails 5.1.1, Nginx, and Passenger, PostgreSQL on Ubuntu 16.04 in 2017

Installing RVM

First install mpapis public key:

gpg — keyserver hkp://keys.gnupg.net — recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

Install RVM:

\curl -sSL https://get.rvm.io | bash -s stable

The output will advice you to run a following type of code. If the output is different from the code below, run the output instead.

source ~/.rvm/scripts/rvm

This will load RVM.

Confirm that RVM is installed by command:

rvm -v

Output should look something like this

rvm 1.29.1 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]

Installing Ruby

Install a ruby version of your choice

rvm install <ruby_version>

Currently 2.4.1 is the latest:

rvm install 2.4.1

After the installation, see that the version is installed:

rvm list

Confirm that you want to use that version:

rvm use 2.4.1.

Install Ruby On Rails

Install rails gem:

gem install rails -v <rails_version>

Currently 5.1.1. is the latest:

gem install rails -v 5.1.1.

BONUS: Install javascript runtime

sudo apt-get install nodejs

If it doesn’t install the latest version which is ~6, follow these instructions: https://askubuntu.com/a/786279/256643

Install Nginx and Passenger

First PGP key and HTTPS support for APT:

sudo apt-key adv — keyserver hkp://keyserver.ubuntu.com:80 — recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

Add the APT repository:

sudo sh -c ‘echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list’

Update:

sudo apt-get update

Install Passenger and Nginx:

sudo apt-get install -y nginx-extras passenger

Go to /etc/nginx/nginx.conf and uncomment the following line

# include /etc/nginx/passenger.conf;

Save and restart nginx:

sudo service nginx restart

Install PostgreSQL

Update and install:

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib libpq-dev

That’s all. All there’s left to do are configurations.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.