In this tutorial we will cover the steps needed to install Ruby on Rails on your CentOS 6.4, Debian or Ubuntu platform.

Requirements

  • CentOS 6.4, Debian or Ubuntu installed on your computer/server
  • SSH access (Command line access to the server)
  • root privileges
  • Basic skills for working on a Linux environment

Install Ruby

There are few methods which can be used for Ruby installation. In this case we will use rbenv method:

CentOS 6.4:

Due to the fact that some of the required packages might not be available by default you will need first to add the EPEL repository to your Linux platform. This can be done with the following command:

After that we can initiate the Ruby on Rails installation using:

Note: The backslash is added at the beginning of the curl command in order to prevent any issues caused by curl aliases. The installation includes the Rails gem.

Debian/Ubuntu:

We will begin the process with the installation of some package dependencies:

After that we can go ahead and install the Ruby using the following commands:

Install NodeJS on CentOS

The Node.js will be compiled from the latest available source package:

You should configure the compiler and compile the source code:

Bear in mind that the process might take some time. Once done you can install Node.js:

Install NodeJS on Debian/Ubuntu

Debian:

We can install NodeJS with the aptitude default package manager after adding the Weezy Backports repository:

Ubuntu:

We can install NodeJS with the aptitude default package manager after adding the Chris Lea repository:

When NodeJS is already installed on the server we can continue install the Rails gem:

Install MySQL or PostgreSQL

Sqlite3 is included in Ruby on Rails as default database. However it is recommended to use MySQL or PostgreSQL as database engine.

When ready we can continue with the installation of the MySQL service which will be required later:

CentOS 6.4:

Debian/Ubuntu:

and the PostgreSQL service:

CentOS 6.4:

Create PostgreSQL user and password:

While inside the PostgreSQL postgres=# prompt type:

and fill in the desired password for the user. After that you can leave the prompt with \q and type exit.

Debian:

Create PostgreSQL user and password:

While inside the PostgreSQL postgres=# prompt type:

and fill in the desired password for the user. After that you can leave the prompt with \q and type exit.

Ubuntu:

Create PostgreSQL user and password:

Access the PostgreSQL client and set password for the rubyr user:

While inside the PostgreSQL postgres=# prompt type:

Testing the functionality of the application

Prior testing the functionality of the application logout from the current SSH session and log in again. Also make sure that the default Ruby port 3000 is opened on the server:

After that try to create new Rails application:

If you want to use it with MySQL type:

If you want to use it with PostgreSQL use:

If you received an error that said Access denied for user 'root'@'localhost' (using password: NO) then you need to update your myapp/config/database.yml file to match the database username and password.

If everything went well you should be able to access the service through:

where X.X.X.X is your server's IP address, i.e. http://1.2.3.4:3000

An easy way to find your server's IP address is to execute the following command: