Installing Ruby on Rails on linux- 5 mins
We are going to install ruby on rails on Linux. For this tutorial I am using Xubuntu 16.04 LTS.
- What is Xubuntu and why Xubuntu
- Installing ruby
- What is bundler
- Git configuration
- Installing Rails
- Installing database
What is Xubuntu and why Xubuntu
Xubuntu is Linux based distro (distro=a Linux distribution). It is inherited from popular a Linux distro Ubuntu. It’s all about personal preference of which distro you want to use. Difference between Ubuntu and Xubuntu is in their user interface. Whether Ubuntu has Unity interface, Xubuntu use XFCE which is much lighter comparing to former one. All of the command used here will work on ubuntu and other distros based on ubuntu(Lubuntu, Kubuntu, Edubuntu and obviously Xubuntu).
First we have to install some dependencies for ruby. Open terminal (CTRL+ALT+T) and run following commands one by one
There are three methods to install ruby. Popular one is using rbenv which I am going to use here. But there are two different ways you can use- using rvm or from source. Both of them are little bit of complex than rbenv method. From command line go to root path
Now install ruby version 2.4.0
Check if it is installed correctly.
If everything is ok you will see ruby version like this
Now we have to install bundler.
What is bundler?
According to the Official site Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.
So to maintain gem in ruby project bundler keep us out from several harsh trap. It is a must have component for any rails project. Run this command to install bundler
And run this after bundler has installed.
Check this article for in depth git setup.
Now install rails. (Current version is 5.0.1)
voila. It’s done. Now check out our rails version using
Rails comes up with default SQLite database. Though this is OK for little projects. But more robust database like MySQL or PostgreSQL would be a good choice to use. Here I am going to show you the process of installing PostgreSQL and integrate it with rails application.
Install PostgreSQL with required dependencies
Now we have to create database user and password.
Choose an username that is exactly similar to your system user name. If you are login into xubuntu with ‘xyz’ username then create database user with ‘xyz’ name. In some cases if database username doesn’t match with system it shows fatal error. Warning: ERROR(fatal: role does not exist)
Go to command line. Replace ‘xyz’ with your username
Enter PostgreSQL console to set password
Select user to set password
Set password for xyz username and confirm it. Exist PostgreSQL console using
So far so good. Let’s create our first application. Give any name as you like to ‘appname’
-d for database. Default database is SQLite. But we want to use PostgreSQL.
or if you want to use specific version of rails (like 4.2.0) run like this command.
Note: Remember, to install a specific version of rails application you must have that version installed in your system. Running multiple version of rails is a painful issue. So if you do not have any specific reason to use different version stick up with latest version.
Configure database information:
Go to rails project folder and navigate to config/database.yml
Remove comment from following lines (by removing #) and set previously create PostgreSQL username and password. If these lines are not included add them.
Now save and return to console.
Go into application directory
Run command to create database
Fire up rails server
Now from your browser visit http://localhost:3000 to view your application!
If you see the Yay message you are officially running your first rails application.
If you received an error that said Access denied for user ‘root’@’localhost’ (using password: NO) then you need to update your config/database.yml file to match the database username and password.