Last modified: Thu Aug 16 2018 22:49:02 GMT+0800 (Malay Peninsula Standard Time)
The following guide in this chapter was tested on machines running
- Windows 7 Professional 64-bit
- Windows 8.1 Professional 64-bit
If you already have a copy of Ruby and Rails installed on your machine that is not installed based on this tutorial, it is recommended to remove them from your machine and follow the instruction in this tutorial. You may have multiple copies of Ruby version in your machine.
You may follow this video tutorial. To begin, determine your Windows Architecture and obtain the URL to the files from correct table below. If you are using Windows machine, it is recommended for you to use Ruby 2.4.1. The next recommended Ruby version for Windows machine is Ruby 2.2.3. Any other Ruby version between 2.2.3 and 2.4.1 tend to have issue with Windows machine. Refer to next chapter if you would like to install Ruby 2.5.1.
Table 4.1.1: Required files for 32-bits Operating System
|Ruby 2.4.1-2 Installer||rubyinstaller-2.4.1-2-x86.exe|
Table 4.1.2: Required files for 64-bits Operating System
|Ruby 2.4.1-2 Installer||rubyinstaller-2.4.1-2-x64.exe|
Run the Ruby Installer and the screen as shown in Figure 4.2.1 will should show up. Accept the license agreement and proceed to the next step by pressing the “Next” button.
Figure 4.2.1: Ruby 2.4.1 License Agreement
Check “Add Ruby executables to your PATH” and complete the installation by pressing the “Install” button as shown in Figure 4.2.2.
Figure 4.2.2: Ruby 2.4.1 Installation Destination and Optional Tasks
At the end of the screen as shown in Figure 4.2.3, do not uncheck the option that install MSYS2. Press “Finish” to complete the installation and a terminal window shown in Figure 4.3.1 will show up.
Figure 4.2.3: MSYS2 installation option
After the Ruby installation is completed, a terminal window, as shown in Figure 4.3.1, will pop up.
Figure 4.3.1: MSYS2 Installation Window
All the components 1, 2, and 3 are required to be installed. To begin, insert 1 into the terminal. Figure 4.3.2 shows the required files are being downloaded.
Figure 4.3.2: MSYS2 required files are being downloaded
After the installation is completed, a installation window as shown in Figure 4.3.3 will show up. Go through and complete the installation by selecting “Next”.
Figure 4.3.3: MSYS2 64bit setup
At the end of the installation as shown in Figure 4.3.4, uncheck the option “Run MSYS2 now”.
Figure 4.3.4: End of installation of MSYS2
Return to the Terminal Window and enter 2 to run MSYS 2 system update. Figure 4.3.5 shows MSYS2 system update is completed.
Figure 4.3.5: MSYS2 system update succeed
Return to the Terminal Window and enter 3 to run MSYS2 and MINGW development toolchain. Figure 4.3.6 shows MSYS2 and MINGW development toolchain installation is completed.
Figure 4.3.6: MSYS2 and MINGW development toolchain installed successfully.
Exit the program by closing the terminal window.
Run the Ruby Installer and the following screen shown in Figure 4.4.1 will show up.
Figure 4.4.1: Node.js Setup Wizard
Accept the license agreement as shown in Figure 4.4.2 and proceed to the next step by pressing the “Next” button.
Figure 4.4.2: Node.js License Agreement Screen
Complete the installation by going through each steps.
To avoid receiving SSL error when trying to install Rails or pull updates from RubyGems, open a command line window and enter the following commands below.
gem sources -r https://rubygems.org/
gem sources -a http://rubygems.org/
A similar output as shown in Figure 4.5.1 will be generated from the command line tool after you inputted the second command. Figure 4.5.1 shows the second command only. Please run both of the commands.
Input the character y to the command line tool to add
http://rubygems.org/ to sources.
Figure 4.5.1: Output of terminal
Open a command line window and insert the following command below. The command below will install the latest version of Rails.
gem install rails
A similar output as shown in Figure 4.6.1 will be generated from the command line tool.
Figure 4.6.1: Output of terminal while installing Rails
To verify that you have successfully installed both Ruby and Rails, enter the following command. A similar output as shown in Figure 4.6.2 will be generated from the command line tool.
Figure 4.6.2: Ruby and Rails successfully installed.
To create your website, it is highly recommending to create a folder name Code in the Ruby file directory. The purpose the folder Code is to store all your source code folder. The Ruby folder location may vary depending on your Operating System Architecture.
Enter the folder Code and create a sample application name
Blog. Enter the following command to command line window a similar output as shown in Figure 4.7.1 below will be generated.
Rails new Blog
Figure 4.7.1: Generating a new
You may or may not receive
SSL_connect error, as shown in the screenshot below.
SSL_connect error while creating a
It is recommended to not to skip the steps below even if you are not having
SSL_connect error. To resolve this error, navigate to the root of your source code and open
Gemfile using a text editor. Figure 4.7.3 shows a
Gemfile is being opened.
Gemfile (with no extension) is being opened
After opening the
Gemfile, replace https with http as shown in line 1 of Figure 4.7.4 and save the file. The
SSL_connect error should be resolved now.
Figure 4.7.3: https is replaced with http as shown in line 1
To start the Web Server, navigate to the folder of your code and run the follow command below. A similar output as shown in Figure 4.8.1 will be generated from the command line window.
Figure 4.8.1: A Rails server is started.
Insert the URL in your Web Browser based on what you have seen from the terminal window to visit your website. According to Figure 4.8.1,
localhost:3000 is the path to my website. A similar output as shown below will be generated from the command line tool.
Figure 4.8.2: A working Ruby on Rails website
A second command line window is opened to prevent termination of local Web Server. To verify that Ruby and Rails were installed correctly without any errors, use the
scaffold command to generate a simple set of a model, views, and controller for Rails Application.
rails g scaffold User name:string age:integer
A similar output as shown in Figure 4.9.1 will be generated from the command line tool.
Figure 4.9.1: Output of terminal window when a
scaffold command is used.
Run the command rake db:migrate to migrate the database generated by the command
scaffold to local database server. A similar output as shown Figure 4.9.2 will be generated from the command line tool.
Figure 4.9.2: Output of terminal window when a migrate command is used.
Navigate to the index page of newly generated page by entering the path at your browser. The index page of
Users will be generated as shown in Figure 4.9.3.
Users index page
To make sure that the application is working and does not throw any error when new data are committed to the database, press the link New User create a new sample data set. A form will be rendered a shown in Figure 4.9.4. Populate the form with any sample data that you prefer and press Create User.
Figure 4.9.4: New user form
An alert message, as shown in Figure 4.9.5, User was successfully created alert message will be shown on the screen when the data is inserted into the database successfully.
Figure 4.9.5: User was successfully created alert
To redirect to the index page of
Users, press the Back button located under the Age shown in Figure 4.9.5. By looking at Figure 4.9.6, we can see that the
Users index page was being rendered.
Users index page was being rendered from output log
Figure 4.9.7 shows a picture of
Users index page with the data that populated in the form earlier.
Users index page was being rendered
Congratulation, you have successfully installed Ruby on Rails on your own machine!