Thursday, 21 September 2017

Step by step tutorial installing Ruby on Rails 5 on Windows

Step by step tutorial installing Ruby on Rails 5 on Windows


This tutorial will walk you through installing this on a development environment on Windows.

1. Install Ruby on local system.

Most of the stuff you will do from the command line, to get the command line in windows, go to start menu/run and type “cmd”. You will also need to have an Internet connection during the installation as most stuff is getting updated via the Internet.

Latest ruby version you can download from here 

If you are going to install 2.4.X than no need to install Development KIT. It’s very easy to install. When installing, click check boxes that ask you to associate Ruby with .rb files and add Ruby to the PATH. Do remember where you installed Ruby, it will come in handy later. Once installed, from the command line type.

ruby -v
Step by step tutorial installing Ruby on Rails 5 on Windows

and you should see something like this: ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32]. If you see “Command not found”, make sure that you reload the command (close & open new) window after the install.

You can run a Ruby statement at the command prompt by using -e option by typing …

ruby -e "puts 'This is ruby test'"
Step by step tutorial installing Ruby on Rails 5 on Windows


2. Update Gems: A gem is a Ruby package.  And RubyGems is like a package manager/installer.
To make sure that you have the latest version of Ruby Gems you can update it by …

gem update --system
It could take 2-3 mins to update. Once updated, from the command line type.

gem -v
Step by step tutorial installing Ruby on Rails 5 on Windows

3. Install Rails: Simply type in cmd: 

gem install rails
Step by step tutorial installing Ruby on Rails 5 on Windows

When our installation completed, we had new gems installed.   Run “gem list” again and see a whole bunch of new gems were installed.  It includes the Rails gem as well as gems like actionpack and activerecord and others that are part of Rails.

Once installation completed, run below command in cmd:

rails -v
Step by step tutorial installing Ruby on Rails 5 on Windows

4. Create your first Rails project:

Make a new directory, let's creates Demo. In your cmd type “cd path/to/your Demo folder”

We are now going to generate a new Rails application. At the command prompt, navigate to the Demo folder.  It is best to generate your Rails app here.We’ll call our Rails app "rubypoc", so we type …
rails new rubypoc
Step by step tutorial installing Ruby on Rails 5 on Windows


By default this will create the rubypoc Rails application set to use the sqlite database.  If you wanted it to use MySQL or other database, then you type …

rails new rubypoc -d mysql
The “-d mysql” tells Rails that we intend to use MySQL database for this app.  If we had left it out, it would have defaulted to using SQLite for the database.

See that it had created the "rubypoc" folder in “Demo”.  This is your rails application.  If you ever want to delete this Rails application, delete the "rubypoc" folder.

Step by step tutorial installing Ruby on Rails 5 on Windows


Inside the rails application is a “public” folder.  This is the Rails public folder that will be exposed to the public via the webserver.

5. Run WebServer:

Rails comes with its own web server, so no need to set up apache. The default web server is Puma.
Now goto rubypoc folder using cd rubypoc in cmd and run below command.

rails server
Step by step tutorial installing Ruby on Rails 5 on Windows

You might get a Windows Security Alert, we choose to select the options as shown below and allow access.

Step by step tutorial installing Ruby on Rails 5 on Windows



From the Puma console, we see that Puma webserver started on port 3000.  It also tells us to use Ctrl-C to stop server.

6. Run application in browser: 

we can point our browser to http://localhost:3000 to see our first Rails web application.  localhost is same as 127.0.0.1 which is the IP address to refer to own local development machine. 

You should see the Rails page.

Step by step tutorial installing Ruby on Rails 5 on Windows



Bingoooo...you are up for rails project.

In next tutorial, I will discuss on how MongoDB will configure with Rails project.

2 comments: