Part1. Set up environments for Ruby on rails on Linux server

Hi guys, welcome to my blog for ruby on rails. I am pleasure to talk with you guys about ruby on rails. Before I talk about detail of Ruby on Rails, let’s start with building a development environment.

To install ruby and rails on your laptop, I am going to use Ubuntu Linux that is used in OS course. If you don’t want to use it for Ruby on rails, I am welcome to use any version of Linux, but I recommend to use Ubuntu or Debian Linux. This is because the installation commands may differ depending on the operating system. As a prerequisite, you need to have a basic knowledge of the Linux operating system, such as how to use basic commands and how to use the vi editor.

1.1 Installing Ruby on Ubuntu Linux

First, let’s proceed with installing Ruby assuming everyone is using the Ubuntu Linux operating system. To install Ruby on Rails, you need to install a manager program called RVM first. The Ruby Version Manager (RVM) is a service that makes it easy to install Ruby. This RVM is a program that simplifies the installation process of Ruby, and also makes it possible to manage multiple versions of Ruby simultaneously. To install Ruby easily, you need to install RVM first. After running Chrome, you can browse RVM in Google or go to the following link: https://rvm.io

Copy the link of the red box!

The same screen as the above screen shot will appear. You must copy the commands in the red box to the screenshot.

$ \curl -sSL https://get.rvm.io | bash -s stable

However, If you try to use this command, the following error occurs. This is because we do not have a program to run curl on Linux.

Errors!

Do not panic, the following command will install the curl program.

$ sudo apt-get update
$ sudo apt-get install curl

Then, If you run the previous command after installing curl, as shown in the figure below, a brilliant message pops up and RVM installation is completed.

Done with Installing RVM!

Then type the following on the terminal and press Enter:

$ source .bash_profile

Now it is time to install Ruby in earnest using RVM. On the terminal, type the following and press Enter:

$ rvm install 2.0.0

It means I will install Ruby 2.0.0. This will start the installation with a more brilliant screen as shown below. It will take some time to complete the installation, so let’s wait:

Check the complete message :)

To verify that Ruby is installed correctly, type the following command and press Enter:

$ ruby -v

It is a command to check the installed version of Ruby. If it comes out as shown below, it is properly installed!

You must see this message to verify installation

1.2 Installing Rails on Ubuntu Linux

Now that you’ve installed Ruby, it’s time to install Rails. Rails is the most widely used server framework based on the Ruby language.

To install Rails, type the following on the terminal and press Enter:

$ gem install rails --version 4.0.1 --no-ri --no-rdoc

It means I will install version 4.0.1 of Rails. That — no-ri — no-rdoc suffixed is meaning that they would not install various manuals and documents related to Rails. This will speed up the installation of Rails. At first, it seems like no message appears, but you have to wait with faith.

If you see ‘Successfully installed rails-4.0.1’ at the end of the screen as shown below, you have successfully completed the installation.

To verify that Rails is properly installed, type the following command and press Enter:

$ rails -v

It is a command to check the version of installed Rails. If it comes out as shown below, it is properly installed:

Done with installing rails framework!

1.3 Creating a Rails project and running the server

To test whether Rails works properly, I will create a Rails project. The ‘project’ here is the unit of the web service that you will be building in the future.

To create a new Rails project first, type the following on the terminal and press Enter:

$ rails new project1 --skip-bundle

This will create a new Rails project directory as shown below:

Enter the project directory you just created:

$ cd project1

Next, you need to add some content to a file named Gemfile in the current project directory. On the terminal, type the following and press Enter:

$ echo "gem 'therubyracer'" >> Gemfile

The meaning of this command will be explained in another post. Next, type the following on the current project directory and press Enter.

$ bundle install

If the command is executed normally, you can see ‘Bundle completed!’ Message at the end of the screen as shown below.

Bundle complete!

Note

If you have any error while installing bundle, you should try this code:

sudo apt-get install g++

And try bundle install again. It will be solution for this problem.

Now it is time to run the server properly. So far, the process of connecting to the server and making a series of settings has been a preparation for running the server. From the moment you start the server on the project directory, it receives the client’s request and delivers the service you created to the client.

To run the server, type the following command in the current project directory and press Enter.

$ rails s

The server is started for the project by rails s command. At this time, the server automatically exchanges requests with the client through port 3000. If the server is running normally, you can see the message shown below

Now run Browser, type ‘localhost: 3000’ in the address bar and hit enter. If the screen shown below is successful, All of setting is done successfully.

Setting is done!

If you want to stop running the server, press Ctrl + c in this state. Then the server will stop running with the following message:

Stop running server

James Jeonggyu Kong

Written by

ITSD student in SAIT, Calgary!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade