0

Ruby on Rails (RoR) is an open supply internet utility framework, printed underneath the MIT License. It’s a server-side internet utility framework that follows the MVC (Mannequin-View-Controller) idea.

Rails are offering default constructions for the database, internet service, and internet pages. Greater than 3000 builders have contributed code to the Rails framework and there are lots of well-known purposes primarily based on Rails, comparable to Github, Airbnb, Soundcloud and so on.

On this tutorial, I’ll present you the steps to put in Ruby on Rails on Ubuntu 18.04 LTS. We are going to present you set up and configure Rails with a PostgreSQL database, and create a brand new first undertaking with Rails.

Conditions

  • Ubuntu 18.04 LTS
  • Root privileges

What we’ll do?

  1. Set up RVM (Ruby Model Supervisor)
  2. Setup Ruby
  3. Set up Nodejs
  4. Configure Ruby Gem
  5. Set up Ruby on Rails
  6. Setup PostgreSQL Database for Rails Improvement
  7. Create Your First App with Rails and PostgreSQL

Step 1 – Set up RVM (Ruby Model Supervisor)

RVM (Ruby Model Supervisor) is a command-line instrument primarily based on Bash and Ruby to handle the ruby set up. RVM lets you set up and configure a number of ruby variations on one system.

Step one we’ll do is to put in the rvm packages utilizing the installer script.

Add the rvm key to the server.

gpg –keyserver hkp://keys.gnupg.internet –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Set up the rvm secure model by operating the command under.

curl -sSL https://get.rvm.io | bash -s secure –ruby

The command will mechanically set up packages required, and set up the most recent secure rvm model.

After the set up is full, run the next command.

supply /usr/native/rvm/scripts/rvm

Install RVM

Now you should utilize the rvm command to handle the ruby model.

rvm model

Step 2 – Setup Ruby Newest Model

The newest model of ruby at this present day is Ruby 2.5.1, and it will likely be mechanically put in throughout the rvm set up, when there isn’t any ruby bundle on the system.

On this step, we’ll arrange the default ruby model on the Ubuntu system.

Replace the rvm to the most recent secure model.

rvm get secure –autolibs=allow
usermod -a -G rvm root

Now examine all out there ruby variations.

rvm listing identified

And you’re going to get lots of out there variations of ruby – set up the most recent secure model Ruby 2.5.1 utilizing the rvm command as proven under.

rvm set up ruby-2.5.1

In spite of everything set up is full, make the ruby 2.5.1 as a default model on the Ubuntu system.

rvm –default use ruby-2.5.1

Examine the Ruby model.

ruby -v

Now you will notice ruby 2.5.1 is default ruby model on the Ubuntu 18.04 system.

Setup Ruby Latest Version

Step 3 – Set up Nodejs

Ruby on Rails requires a JavaScript runtime to compile the Rails asset pipeline. And for the Rails improvement on Ubuntu Linux, it is best to put in and utilizing Nodejs because the Javascript runtime.

Add the nodejs nodesource repository to the system.

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –

Set up the most recent model nodejs 10 and a few extra packages utilizing the apt command under.

sudo apt set up -y nodejs
sudo apt set up gcc g++ make

The nodejs 10 has been put in on Ubuntu 18.04 system.

Step 4 – Configure Ruby Gem

RubyGems is a Ruby Package deal Supervisor, coming with the gem command-line instrument. It is mechanically put in after we set up Ruby on the system.

Replace gem to the most recent model and examine it.

gem replace –system
gem -v

Observe:

That is non-compulsory, we are able to disable gem to put in documentation on each ruby bundle set up. Just by including the configuration to the ‘.gemrc’ configuration file.

echo “gem: –no-document” >> ~/.gemrc

Step 5 – Set up Ruby on Rails

On this tutorial, we will likely be utilizing the most recent secure Ruby on Rails 5.2.0. We are going to set up Rails utilizing the gem ruby bundle supervisor.

Set up Ruby on Rails 5.2.Zero utilizing the command under.

gem set up rails -v 5.2.0

After the set up is full, examine the rails model.

rails -v

And following ought to the end result.

Install Ruby on Rails

Ruby on Rails 5.2.Zero has been put in on Ubuntu 18.04 LTS.

Step 6 – Setup PostgreSQL Database for Rails Improvement

By default, Ruby on Rails is utilizing the SQLite database. It helps many databases system, together with MySQL, SQLite, and PostgreSQL. And for this information, we will likely be utilizing PostgreSQL.

Set up the PostgreSQL database utilizing the apt command under.

sudo apt set up postgresql postgresql-contrib libpq-dev -y

In spite of everything set up is full, begin the Postgres service and allow it to launch everytime at system boot.

systemctl begin postgresql
systemctl allow postgresql

Subsequent, we’ll configure a password for the Postgres consumer, and create a brand new consumer for the Rails set up.

Login to the ‘postgres’ consumer and run the Postgres shell.

su – postgres
psql

Change the Postgres password utilizing the question under.

password postgres

Kind your password and the password for postgres consumer has been added.

Now we’ll create a brand new position for our rails set up. We are going to create a brand new position named ‘rails_dev’ with the privilege of making the database and with the password ‘aqwe123’.

Run the Postgres question under.

create position rails_dev with createdb login password ‘aqwe123’;

Now examine all out there roles on the system.

du

And you’re going to get the ‘rails_dev’ position on the listing.

Setup PostGres

PostgreSQL set up and configuration for Rails Improvement has been accomplished.

Step 7 – Create Your First App with Rails and PostgreSQL

Ruby on Rails offers a command-line ‘rails’ for bootstrapping our first rails utility.

Create a brand new undertaking ‘myapp’ with default database ‘PostgreSQL’ by operating rails command under.

rails new myapp -d postgresql

Now you will notice the ‘myapp’ listing, go to that listing and edit the database configuration file ‘database.yml’ utilizing vim editor.

cd myapp/
vim config/database.yml

There are totally different configuration sections for every setup – Improvement, Testing, and Manufacturing.

Within the improvement part, uncomment these line and alter the worth as under.

username: rails_dev
 password: aqwe123
 host: localhost
 port 5423

For the testing part, paste these configurations underneath the testing part.

  host: localhost
   port: 5432
   username: rails_dev
   password: aqwe123

Save and exit.

Now generate the database and ensure there isn’t any error.

rails db:setup
rails db:migrate

When all setup is full, begin the default puma rails internet server utilizing the command under.

rails s -b 192.168.1.10 -p 8080

The primary rails undertaking will likely be operating on the IP deal with ‘192.168.1.10’ with port 8080.

Create Ruby App

Open your internet browser and sort the server IP deal with on the deal with bar.

http://192.168.1.10:8080/

You’re going to get the default rails undertaking homepage as under.

Ruby on Rails App is working

Subsequent, we’ll take a look at to create easy CRUD with PostgreSQL database on rails.

Run the rails command under.

rails g scaffold Put up title:string physique:textual content
rake db:migrate

Run the puma internet server once more.

rails s -b 192.168.1.10 -p 8080

And open the net browser with the URL under.

http://192.168.1.10:8080/posts/

Now you’re going to get the straightforward CRUD type.

Test App written in RoR

And following is my end result after making a easy submit.

Find out how to Set up Ruby on Rails on Ubuntu 18.04 LTS 10

Ruby on Rails set up with PostgreSQL database on Ubuntu 18.04 LTS has been accomplished efficiently.

DNS as Quick As Potential

Previous article

One other Home windows 10 SKU is on its manner, this time for distant desktops

Next article

You may also like

Comments

Leave a Reply

More in Linux