ruby-on-rails-5 Getting started with ruby-on-rails-5 Setup Ruby On Rails on Ubuntu 17.04 Zesty Zapus


This will take about 30 minutes. We will be setting Ruby on Rails Development Environment on Ubuntu 16.10 Yakkety Yak.
You'll want to download the latest Desktop version here:

Open up your terminal using Ctrl + Alt + T.

Installing Ruby

The First step is to install Dependencies For Ruby.

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs

We will be using Ruby version 2.4.0 and it is recommended. Install Ruby using one of the three methods. Each have their own benefits, mostly people prefer rbenv but if you are familiar with rvm then go for it.

Note: Only rbenv users need to run rbenv rehash after installing bundler.

Installing with rbenv:

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

git clone ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.4.0
rbenv global 2.4.0
ruby -v

Then install Bundler:

gem install bundler

Use rbenv rehash after installing bundler.

Installing with rvm:

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

Then install Bundler:

gem install bundler

Installing with source:

tar -xzvf ruby-2.4.0.tar.gz
cd ruby-2.4.0/
sudo make install
ruby -v

Then Last step is to install Bundler:

gem install bundler

Installing Rails

Rails ships with so many dependencies these days, we're going to need to install a JavaScript run-time like NodeJS. This lets you use Coffee-script and the Asset Pipeline in Rails which combines and minifies your JavaScript to provide a faster production environment.

Install NodeJS using the official repository:

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Now install Rails 5.0.1:

gem install rails -v 5.0.1

If you are using rbenv then run the following command to make rails executable available:

 rbenv rehash

Now Rails is Installed, Run rails -v to make sure rails installed properly:

rails -v
# Rails 5.0.1

If you are getting a different result for some reason, it means that your environment may not be setup properly.

Setting Up PostgreSQL

Rails ships with sqlite3 as the default database. Chances are you won't want to use it because it's stored as a simple file on disk. You'll probably want something more robust like MySQL or PostgreSQL.

There is a lot of documentation on both, so you can just pick one that seems like you'll be more comfortable with.

sudo sh -c "echo 'deb xenial-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.5 libpq-dev

PostgreSQL installation doesn't setup a user for you, so you'll need to follow these steps to create a user with permission to create databases. Feel free to replace Hizqeel with your username.

sudo -u postgres createuser hizqeel -s

# If you would like to set a password for the user, you can do the following
sudo -u postgres psql
postgres=# \password hizqeel