Setup Ruby on Rails (Mac/Linux)

What is Ruby on Rails?

Ruby on Rails is an open-source framework to build powerful web applications. While Rails (Ruby on Rails) being the framework, the language it is based on is Ruby. Rails was created in 2004 by David Heinemeier Hansson while Ruby was created a decade ago (in 1993) than Rails. Rails is based on the MVC (Model-View-Controller) design pattern and supports multiple types of servers and databases. It also has its own server; WEBrick. The default database for Rails is SQLite3, a server-less database.

What is RubyGems?

RubyGems is a package manager for the Ruby language. It contains bits and pieces of code which you can plugin to your Ruby on Rails site. Rails is also a gem. You can install Rails through RubyGems. RubyGems is used to distribute Ruby based programs and libraries.

For Mac OS X users

1st step: Install “homebrew” (The missing package manager for MacOS) by copying and pasting the below command in your terminal. This command can also be found at the Homebrew website, https://brew.sh/.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

If you already have Homebrew installed, this step would not be necessary.

2nd Step: Once Homebrew has finished the installation, on the same terminal type the following command to install ruby

brew install ruby

Once the installation is complete, type ruby -v on the terminal to find out whether you have installed the latest version of ruby. The version of ruby installed will be displayed as the output of this command.

3rd Step: After the Ruby installation you are able to use Ruby’s own package manager. In order to install the Rails Framework, open the terminal and type the following command.

gem install rails

Once the installation is complete, the Rails version installed can be checked by typing the command rails -v on the terminal.

To check the versions of both Ruby and Rails at once, open the terminal and type:

ruby -v && rails -v

4th Step: Next you need to install the RVM (Ruby version manager). This installation is also pretty straightforward. (Similar to installing Homebrew). Visit the link https://rvm.io/rvm/install to copy the command to install the stable version of RVM. The command is as follows.

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Type the above command on the terminal and run it to install RVM. To start RVM you need to run,

source /Users/(username)/.rvm/scripts/rvm

If the server starts correctly, the above command should execute without errors. Afterwards type rvm –help on the terminal, and if it displays a list of help options, it means that RVM has installed successfully.

That concludes the setting up of Ruby on Rails on Mac OS X.

For Linux users (Ubuntu)

1st Step: Type the below command to perform a quick update in order to make sure all packages we download are up-to date.

sudo apt-get update

2nd Step: Next you need to install Curl. Curl is a client which gets files and folders from servers using protocols such as FTP, HTTP. The below command would install Curl.

sudo apt-get install curl

Once the installation is complete, the version of Curl can be checked by typing the command curl –version on the terminal.

3rd Step: The next step would be to install RVM (Ruby version manager). To install RVM type the below command on the terminal and run it.

\curl -sSL https://get.rvm.io | bash -s stable

Next the RVM server needs to be started in order to perform operation using RVM. The below command will start the RVM server.

source /home/ubuntu/.rvm/scripts/rvm

If RVM is installed correctly the command rvm -v would output the version of RVM installed.

If an error is displayed instead of the version, the below command would fix the error.

curl -sSL https://rvm.io/mpapis.asc | gpg2 --import

In order for RVM to perform well, there are certain dependancies which needs to be installed as well. The command rvm requirements will automatically download these dependancies.

4th Step: Ruby installation is the next step. Make sure to install the latest version of Ruby by the following command on the terminal. (In here the version is 2.4.1)

rvm install ruby-2.4.1

If any errors occur, or any dependancies fail to install, update RVM by using the command rvm get head. Afterwards type and run rvm requirements on the terminal in order to make sure that all RVM dependancies are installed successfully. This should output a success message on the terminal. Afterwards reinstall Ruby through the command rvm reinstall 2.4.1

Next, in order to use the installed Ruby version, type and run the following command on the terminal.

rvm use 2.4.1 --default

5th Step: Next we need to make sure that we have all the components we need for Ruby. RubyGems needs to be installed for this using the command below.

rvm rubygems current

Afterwards Rails can be installed using gems through the below command on the terminal.

gem install rails

The versions of Ruby and Rails installed can be checked using the commands ruby -v and rails -v respectively.

That concludes the setting up of Ruby on Rails for Ubuntu.

Thank you!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: