In this tutorial we will learn to install install Ruby on Rails on CentOS 7. For installing Ruby we will use rbenv.
For installing Ruby on Rails, you will need to have a server with CentOS 7 installed. Additionally you will need root access on your server. In this tutorial we will be using the root account to run the commands. If you are not logged in as the root user, you can either use sudo command before all the commands, or you can use su command to login as root.
Before installing any package, it is a good practice to update the system and it's repositories using the following command.
yum -y update
Once the system is updated, we can proceed with the installation of rbenv by installing the required packages using the following command.
The above command will install Git along with some tools to compile the source and install Ruby. Now run the following command as the user in which you want to install Ruby, as rbenv separately install Ruby on each user account. Run the following command to install rbenv.
The above commands will download and install rbenv and then it will set an environment variable path to rbenv, next it will configure your system to start automatically and finally it will apply the changes immediately.
Next fetch Ruby builds so that you can install it with rbenv. Run the following commands.
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 2.3.1
You can install as many version of Ruby you want using the above command. rbenv keeps track of the versions separately. To make a version of Ruby as global Ruby versions for all the shells in the system, run the following command.
rbenv global 2.3.1
If you want to use another version of Ruby for your local shell, you can run the following command.
rbenv local 2.2.1
This will override the global configuration for your local shell, you can now use other version of Ruby. To unset the local version of Ruby back to the global version, you can unset the local version using the following command.
rbenv local --unset
You can view the list of all the Ruby versions installed on your system using the following command.
You will see output similar to this.
* 2.3.1 (set by /root/.rbenv/version)
Shows the current default version of Ruby in your system.
You can also check the current version of Ruby on your shell using the following command.
You can also remove a Ruby version from your system using following command.
rbenv uninstall 2.2.1
The above command will remove the specified version of Ruby from your system, You will see following output.
[root@liptan ~]# rbenv uninstall 2.2.1
rbenv: remove /root/.rbenv/versions/2.2.1? y
To install Rails on your system you can run the following command.
gem install rails
The above command will install latest version of Rails into your system. 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.
Once done, you can check if Rails is installed correctly using the following command.
The above command will show you the version of Rails installed in your system, you will see output similar to this.
[root@liptan ~]# rails -v
To install Node.js on CentOS, run the following command.
yum -y install epel-release
yum -y install nodejs
By default Rails uses SQLite as its default database, but it is recommended that on production environment you should use either MySQL or PostgreSQL as SQLite is not capable of handling high traffic and huge data size. In this example we are going to use MySQL as database server for Rails application. To install MySQL in your system run the following commands.
yum -y install mariadb-server mariadb-devel
Now start and enable MariaDB using following command.
systemctl start mariadb
systemctl enable mariadb
Now secure your MariaDB installation using the following command.
It will ask you for various configurations during script run, provide the information accordingly.
Now finally install MySQL adaptor to connect Rails with MySQL server using the following command.
gem install mysql2
Creating a New Application
To create a new Ruby on Rails application, run the following command.
rails new myrailsapp -d mysql
In this example we have taken our app name as myrailsapp, but you can use any name according to your choice.
If you want to create the database of your new application using SQLite, do not use -d mysql argument while creating your app. You can simply use rails new myrailsapp.
If you have choosed to use MySQL database then you will need to edit config/database.yml file to provide database server credentials. Use the following commands to edit the file.
If you don't have nano installed, you can run yum -y install nano to install nano editor. Once you open the file in your favorate editor, find the following lines.
If you find your cPanel disk space filling up, or an email address has hit its disk space quota, cPanel has a helpful built in Email Disk Usage tool. This will provide you with a simple to understand breakdown of how much disk space each folder for a particular email...
Although WHM will normally automatically keep itself up to date, you may want to manually check for server updates / push through an update that is pending, or it may be that you have automatic updates switched off on your cPanel server. In this guide we will show you how...
You may sometimes need to manually adjust the PHP settings on your cPanel server – for example if a site is hitting the PHP memory, or file size upload limit. WHM allows you to quickly change the settings of any PHP version installed on the server when needed, using the...