How to Install Ruby on Rails

Phrase
Software Localization Tutorials
5 min readMay 18, 2016
For everyone who wants to use the phrase gem and doesn’t know what Ruby is: Learn how to install Ruby — the interpreter of the Ruby programming language — on OS X, Linux and Windows.

What Is Ruby?

Ruby is a dynamic, object-oriented programming language that was created in 1995 by Yukihiro Matsumoto, a Japanese developer. Ruby was influenced by languages such as Smalltalk and Eiffel. Its main philosophy is aimed towards the developer’s happiness and productivity. Yukihiro wanted to present a language that’s comfortable to use, easy to understand, and that doesn’t try to surprise you. Therefore, programs in Ruby can often be read like a plain English text. For example: redirect_to root_url unless current_user.admin?.

Main Ruby Concepts

  • To start off, all major platforms support Ruby: *nix, Mac, Windows
  • Ruby implements a paradigm of object-oriented programming. It has classes, methods, and modules. Nearly everything in Ruby is an object, meaning that you may write something like 5.times { puts 'hi!' }
  • Ruby is a dynamically-typed language: it means that the developer doesn’t need to declare variables before using them. While this approach has some downsides (Ruby isn’t the fastest language in the world), programs become more compact and understandable
  • Also, due to Ruby’s dynamic nature, it’s possible to implement metaprogramming. Basically, metaprogramming involves code that produces code, meaning that you may define new classes and methods during runtime. It’s a very powerful technique that allows writing relatively large programs with little code. Of course, with great powers comes great responsibility. Therefore, metaprogramming requires some experience and advanced knowledge of the language
  • Metaprogramming, in turn, allows to create beautiful domain-specific languages built on top of Ruby. For example, RSpec, a popular solution for automated testing, is written in pure Ruby and allows to say something like expect(user.name).to include('Jo'). Even non-developers will easily understand what this line means!

Some Ruby Features

  • Ruby has a great standard library implementing tools to send HTTP requests, parse JSON/XML/YAML, work with date/time and more
  • If built-in tools are not enough for you, Ruby has a great community that produced tons of free and open source solutions. Looking for even faster JSON parser? Here you go. Need a fast web server? Go grab it. Wish to build graphical interfaces? Build it! Want to read some jokes about Chuck Norris? Not a problem either!
  • Ruby’s community has also produced detailed documentation, tutorials, examples and best practices. If you ever require help, most likely you’ll get it.

Ruby is steadily evolving: New major versions of the language emerge every year. While it may not be the most popular language in the world, at least 10% of respondents said they were using it. And also, it’s one of the most top-paying languages!

It’s on Rails!

No doubt, Ruby’s popularity in recent years has been fueled by the emergence of the Ruby on Rails web framework in 2005. Ever since it has gained a lot of traction from newcomer and seasoned developers. Just like Ruby, Rails is aimed at high productivity and enables coders to create complex web applications by presenting all the necessary tools. This framework implements the MVC paradigm:

  • Model manages data, logic, and rules
  • View represents the data
  • Controller acts as a glue between model and view. It gives commands what data to fetch and what view should present it

Rails is still very popular these days, and other web frameworks have borrowed many ideas from it.

Installing Ruby On Windows

PIK

Linux and Mac OS X have a great tool called RVM to manage Ruby versions and gems. There is an alternative for RVM (which is not supported on Windows), PIK. For more reference consult the Github page.

Install Ruby

There is an installer available: Ruby Installer. You will find the installers for different Ruby versions via the download section. After that you will need to install devkit. That is needed in order to build/download gems.

Mac OS X / Linux

RVM — Ruby Version Manager

RVM is the Ruby Version Manager. It is a useful tool to manage several ruby versions and their respective gems. A gem is something like a library that you include in your project like our phrase gem to use our REST API. To get a sense on how it is installed check out the official RVM website.

Next if you want to use RVM in a shell — and we highly encourage you to do so — then you need to add it to your bash_profile with the following entry:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Installing Ruby On Mac OS X Or Linux

If you’re working with either Mac OS X / Linux we strongly encourage you to use RVM.

In order to use it see the section for RVM.

When you have RVM installed there are several steps to follow:

# List all currently available versions:
rvm list known

# We currently recommend a version greater than ruby-1.9.3
# you can also try the ruby-head version
rvm install ruby-1.9.3-p327-turbo

For those who did not install RVM: You can also use homebrew for this.

Note: your gems must be managed by yourself if need be. This can be a time consuming and process. However there are a great deal of sources for this topic.

To install a Ruby version with homebrew. Note that homebrew only has some of the Ruby versions in store.

brew install ruby

Installing The Phrase Gem

First you need to create a project folder or go to your current working project (For first time usage we strongly recommend some kind of testing environment where you can get familiar with the phrase gem without breaking anything)

mkdir my_project
cd my_project

For those using RVM: To enable RVM set the .ruby-gemset directory for RVM and set the Ruby version in the .ruby-version file.

# current working directory into your .ruby-gemset
basename `pwd` > .ruby-gemset

# current ruby version into your .ruby-version
echo "your_downloaded_ruby_version" > .ruby-version

# If you don't know the current Ruby version, you can find it via this command:
which ruby

Go out of your current directory and switch back to it so that RVM recognizes your current working directory. It will do so automatically. Your shell will tell you that it recognized your .ruby-gemset and .ruby-version files.

cd ..
cd my_project

Now install the phrase gem:

# Installs the gem
gem install phrase

# or add the gem to your Gemfile when using bundler
echo "source :rubygems"$'\n\n'"gem 'phrase'" > Gemfile

For more details on the installation and usage see the README in the Github repository.

Be sure to subscribe and receive all updates from The Phrase Blog straight to your inbox. You’ll receive localization best practices, about cultural aspects of breaking into new markets, guides and tutorials for optimizing software translation and other industry insights and information. Don’t miss out!

Originally published on The Phrase Blog.

--

--