Ruby on Rails Installation

Introduction

Ruby on Rails is being used for some of most of relevant companies in the world, such as Git Hub, AirBnb, Groupon, Hulu, etc. In addition, there is a high demand for Ruby on Rails on the labor market for web back-ending development. However, there are some languages in the market where you must take into account, before considering to use Ruby in your project.

Here are some Advantages and Disadvantages of developing on Ruby on Rails :

Advantages

  • Uses MVC(model-view-controller) philosophy, in order to separate the application in models, which is easier for developers to add new features and maintenance

  • You don’t need to code all your applications from scratch. You can use RubyGems to install some feature on your website that was already developed before.

  • Language and Gems are well documented online.

MVC-Ruby

Disadvantages

  • Lower performance, mainly, because of use of a great amount of gems.

  • Less popular than Java and PHP, therefore, there are fewer developers than these languages.

Basic Concepts

This post will show how you prepare your machine to start developing using Ruby on Rails.

Before we start to prepare a development environment for Ruby on Rails, there are a few concepts that we should know :

  • Ruby - Created by Yukihiro Matsumoto, Ruby is the programming language used to code. Ruby is a language used for general purposes, not only for web development.

  • Ruby on Rails - is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started.

  • Gem (RubyGems) - is the package manager for the Ruby programing language that provides lots of libraries to your Ruby project. Before you start, it is recommended to check the RubyGems website, to check if the features you want to use on your project is already available.

  • IRB (Interactive Ruby Shell) - is the command line interface with Ruby, which allows interaction with code, when it is running.

How to install Ruby on Windows and Mac

There are a few differences on installing Ruby on Windows and Mac PCs. MacOs after version 10.12 already have Ruby installed, so you will just need to check the version of Ruby on this machine.

Ruby on Mac

Step 1 - Install RubyInstaller (Windows only)

If you don’t have the Ruby installed on your machine, you should download the RubyInstaller from the site https://rubyinstaller.org/ . This also will get the RubyGems along to this package, which will allow installing the web-framework Rails.

RubyInstaller

After installation, check on the CMD if Ruby is installed by using the command: ruby -v

Ruby installed on Windows

*Some Ruby Installer will include the MSYS2, which a Unix-like environment, a command-line interface for those who are used to Unix Shell Script commands. The installation of this component is optional.

Step 2 - Install Rails (Windows/Mac)

Go to the CMD(for Windows) or Terminal(for Mac) and use the command: gem install rails

Rails installed on Windows

Rails installed on Mac

After installation, check on the CMD(for Windows) or Terminal(for Mac) if Rails is installed by using the command: rails -v

Rails installed on Windows

Rails installed on Mac

*Puma WebServer is built-in with the installation of Rails.

Step 3 - Install MySQL and MySQL gem (Windows/Mac)

You will need to configure MySQL on your environment if you to work with a database. Go to https://dev.mysql.com/downloads/mysql/ and configure MySQL server.

MySQL website

After installation, go to the CMD(for Windows) or Terminal(for Mac) and use the command: gem install mysql2

Gem MySQL installed

Step 4 - Choose a text editor (Windows/Mac)

You can use any text editor to code with Ruby. However, I suggest using one colored text editor, in order to make easy to code and identify the elements of Ruby programming language. Here a few suggestion of text editors:

Atom https://atom.io/

Sublime https://www.sublimetext.com/

Notepad++ https://notepad-plus-plus.org/

Step 5 - Create a new project (Windows/Mac)

On the CMD(for Windows) or Terminal(for Mac), choose the folder you want to create a project. After that, use the following command: rails new Ex: rails new helloworld

Now you have a folder with your project created.

Create Ruby Project

Step 6 - Create the database (Windows/Mac)

With the installation of MySQL, there is a command-line called “MySQL XX Command Line Client” that we can use to connect to the database server. Connect to MySQL and create the database by using the following command : CREATE DATABASE ; Ex.: CREATE DATABASE helloworld_database

Then, grant access to your rails application by using the following command :

GRANT ALL PRIVILEGES ON .* TO ‘rails_user’@‘localhost’ IDENTIFIED BY ‘’;

Create DATABASE MySQL

Finally, enter on your text-editor and configure the file database.yml in the config folder. Include in the file the information of the database, user and password passed to MySQL.

Project Folder

database.yml

To test if your project is connecting to the database go to the CMD(for Windows) or Terminal(for Mac), and use the following command: rails db:schema:dump.

This will create a new file called schema.rb in the db folder.

Connect to database by your Rails Web Application

schema.rb created

Step 7 - Launch the project

On the CMD(for Windows) or Terminal(for Mac), go to your project folder and use the command: rails server

Launch Ruby on Rails Web Application on Windows

Launch Ruby on Rails Web Application on Mac

Go to the browser and check if the website is online. On my machine, the address is http://localhost:3000

Ruby on Rails Website on Windows

Ruby on Rails Website on Mac

Congratulations!!! You launched your first Ruby Application!!!

References :

https://prograils.com/posts/top-10-famous-sites-built-with-ruby-on-rails

https://www.netguru.co/blog/pros-cons-ruby-on-rails

https://www.ruby-lang.org/en/about/

http://rubyonrails.org/

https://rubygems.org/

https://www.lynda.com/Ruby-Rails-tutorials/Installing-Running-Ruby-Rails-5-Windows/500550-2.html

Written by Daniel Fonseca