Last modified: Thu Aug 16 2018 22:49:02 GMT+0800 (Malay Peninsula Standard Time)
The following guide was tested only on machine running Ubuntu 16.04 64-bit. It should work on any machine that runs on 32-bit. This may or may not work on earlier version of Linux or distribution.
You may follow this video tutorial.
Open a terminal as shown in Figure 2.1.1 by pressing the Ubuntu logo in your top left navigation bar.
Figure 2.1.1: Terminal Window icon in Applications
The root directory of the terminal as shown in Figure 2.1.2 is Home directory.
Figure 2.1.2: Terminal Window and root directory in Ubuntu
Next, enter the following command below to begin your installation. Enter the command as in a line. Do not hit enter until you are done entering it.
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev libsqlite3-dev
After the command above is inserted, your user account’s password will be be request. When the screen, as shown in Figure 2.1.2, is requesting for user input, enter
Y to download and install the required files.
Figure 2.1.2: Ruby Installation
After the installation is complete, run the command below to check if Ruby is installed successfully. Figure 2.1.3 shows the input and the output text from the Terminal Window. If the code does not return a Ruby version, please repeat the installation process
Figure 2.1.3: Ruby version shown in Terminal Window
To download Rails, enter the code below in a Terminal Window. Figure 2.2.1 shows the input and the output text from the Terminal. This operation can take up to 5 minutes depending on your computer’s processing speed and Internet connection.
sudo gem install rails
Figure 2.2.1 Input and the output text from the Terminal
After the installation is complete, run the following code to check if Ruby is installed successfully. Figure 2.2.2 Rails version in the Terminal Window. If the code does not return a Rails version, please repeat the installation process
Figure 2.2.2: Rails version shown in Terminal Window
To download Node.JS, enter the code below in a Terminal Window. Figure 2.3.1 shows the Node.JS installation in the Terminal Window. The operation may require you to respond. Respond y if there is a screen asking for a user permission to download the files.
sudo apt-get install nodejs
Figure 2.3.1 Node.JS installation
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 2.4.1 below will be generated.
rails new Blog
Figure 2.4.1 Generating a new Blog
To start the Web Server, navigate to the folder of your code and run the follow command below. Figure 2.5.1 shows a Rails server is running.
Figure 2.5.1: A Rails server is running
Insert the URL in your Web Browser based on what you have seen from the Terminal Window to visit your website. Figure 2.5.2 shows a running Ruby on Rails website. Based on the Figure 2.5.1, localhost:3000 is the path to my website.
Figure 2.5.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 2.6.1 will be generated from the command line tool.
Figure 2.6.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 2.6.2 will be generated from the command line tool.
Figure 2.6.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 2.6.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 2.6.4. Populate the form with any sample data that you prefer and press Create User.
Figure 2.6.4: New
An alert message, as shown in Figure 2.6.5, User was successfully created alert message will be shown on the screen when the data is inserted into the database successfully.
Figure 2.6.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 2.6.5. By looking at Figure 2.6.6, we can see that the
Users index page was being rendered.
Users index page was being rendered from output log
Figure 2.6.7 shows a picture of
Users index page with the data that populated in the form earlier.
Users index page
Congratulation, you have successfully installed Ruby on Rails on your own machine!