In this tutorial we will show you how to install and configuration of Ruby on Rails on your CentOS 7 server. For those of you who didn’t know, Ruby on Rails (RoR) is a framework written in the Ruby programming language that allows you to use Ruby in combination with HTML, CSS, and similar programming languages. It is used by many developers since it makes the application development very simple.
This article assumes you have at least basic knowledge of linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Ruby on Rails on a CentOS 7 server.
Install Ruby on Rails on CentOS 7
Step 1. First let’s start by ensuring your system is up-to-date.
yum clean all
yum -y update
Step 2. Installing Rbenv.
Rbenv is a ruby version management tool. We will use this to install and manage our Ruby installation. So let’s start the installation of rbenv:
yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
Now we are ready to install rbenv. The easiest way to do that is to run these commands:
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
This installs rbenv into your home directory, and sets the appropriate environment variables that will allow rbenv to the active version of Ruby.
Step 3. Installing Ruby.
You need to determine the version of Ruby that you need. You can list available Ruby versions for installation with the following command:
rbenv install -l
As we can see on the list that the latest stable version is 2.3.1, you can install Ruby using the following command:
rbenv install -v 2.2.1
rbenv global 2.2.1
You can verify the installation using the command below. It will show you the version and details of the installation:
If you do not want rubygems to install the documentation for each package locally, run the below command:
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
Now, Install the bundler gem which is used to manage your application dependencies using the following commands:
gem install bundler
Step 4. Installing Rails.
To install Rails on your system you can run the following command:
gem install rails
After installing the any package through gems it is important to run the following command so that it can install shims for all Ruby executables known to rbenv, which will allow you to use the executables:
To check the version of Rails, you can execute the command below:
[email@example.com ~]# rails -v
yum -y install epel-release
yum -y install nodejs
Step 6. Create test application.
To make sure that the Ruby on Rails installation completed successfully, We can create a test application by following the steps below:
rails new testapp
Now start your Rails server using the following command:
rails server --binding=Your-Server-IP
Visit http://Your-Server-IP:3000 from your browser. If you see the “Welcome aboard” message, your Ruby on Rails installation is successful.
Congratulation’s! You have successfully installed Ruby on Rails. Thanks for using this tutorial for installing Ruby on Rails in CentOS 7 systems. For additional help or useful information, we recommend you to check the official Ruby on Rails web site.