Rails 5 Basics : Running the Server

Objective

  • To run your rails application on your machine and check your application's environment.

Steps

Step 1

Check the versions of installed ruby, rails and ruby gems by running the following commands in the terminal:

$ruby -v

The output on my machine is : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]

$rails -v

The output on my machine is: Rails 5.0.0.alpha

$rails c
Loading development environment (Rails 5.0.0.alpha)
a2.2.3 :001 > Rails.version
 => "5.0.0.alpha" 

You can also check the version in the rails console.

$gem env

The output on my machine is: RUBYGEMS VERSION: 2.4.5.1

Step 2

Change directory to where you want to work on new projects.

$cd projects

Step 3

Create a new Rails project called blog by running the following command.

$rails new blog

Step 4

Open a terminal and change directory to the blog project.

$cd blog

Step 5

Open the blog project in your favorite IDE. For Textmate :

$mate .

Step 6

Run the rails server:

$rails s

Step 7

Open a browser window and enter http://localhost:3000. Welcome page is displayed as the home page.

Step 8

You can shutdown your server by pressing Control+C.

Step 9

Click on the 'About' link and check the versions of software installed. If the background of the about section is yellow, installation is fine. If it is red then something is wrong with the installation.

Explanation

The rails generator automatically runs the Bundler command bundle to install your application dependencies by reading the Gemfile. The Gemfile contains all the gems that your application needs. rails s (s is a short-cut for server) runs your server on your machine on port 3000.

Summary

In this lesson you learned how to run the server locally. We also saw how to check if everything is installed properly on our machine. In the next lesson you will learn how to create a home page for your web application.


Related Articles


Create your own user feedback survey