INSTALLATION OF RUBY ON RAILS (USING RBENV)

INTRODUCTION

Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

Installation Methods

There are several ways to install Ruby:

  • When you are on a UNIX-like operating system, using your system’s package manager is the easiest way of getting started. However, the packaged Ruby version usually is not the newest one.
  • Installers can be used to install a specific or multiple Ruby versions. There is also an installer for Windows.
  • Managers help you to switch between multiple Ruby installations on your system.
  • And finally, you can also build Ruby from source.

Installing Ruby for Ubuntu 15.04 using Rbenv

Note: The project repository is located on GitHub

Install some dependencies for Ruby

$ sudo apt-get update

$ sudo apt-get install build-essential

alt text alt text

apt-get update: Downloads the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

Install the dependencies required for rbenv with apt-get

$ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev  libffi-dev libgdbm3 libgdbm-dev                                                                                                                                                                            

alt text

Installation of rbenv

These steps are to be completed from the user account which ruby is to be installed.

$ git clone git://github.com/sstephenson/rbenv.git .rbenv

alt text

If bash: git: command not found error arises

alt text

Install git

$ sudo apt-get install git

alt text

From here, you should add ~/.rbenv/bin to your $ PATH so that you can use rbenv's command line utility. Adding ~/.rbenv/bin/rbenv init to your ~/.bash_profile will let you load rbenv automatically. Installation of ruby-build ( a plugin for rbenv through git ),which simplifies the installation process for new versions of Ruby to use the command

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile

source rbenv

$ source ~/.bash_profile

alt text

To check if rbenv was set up properly, enter

$ type rbenv

This displays more information about rbenv

The Terminal displays

rbenv is a function
rbenv () 
{
    local command;    
    command="$ 1";    
    if [ "$ #" -gt 0 ]; then    
        shift;        
    fi;    
    case "$ command" in     
        rehash | shell)        
            eval "$ (rbenv "sh-$ command" "$ @")"            
        ;;        
        *)        
            command rbenv "$ command" "$ @"            
        ;;        
    esac    
}
                                                                                                                                                                             

alt text

Install Ruby

listing all the available versions of Ruby

$ rbenv install --list

The Terminal displays

Available versions:
1.8.5-p52
1.8.5-p113
1.8.5-p114
.................
.................
.................
.................
ree-1.8.7-2012.01
ree-1.8.7-2012.02
topaz-dev                                                                                                                                                

alt text

For example , consider installation of Ruby version 2.3.1, and setting it as default version with the global sub-command:

$ rbenv install 2.3.1
$ rbenv global 2.3.1

alt text

Verify that Ruby was properly installed by checking version number

$ ruby -v

The Terminal displays

ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

Installation of Gems

Gems are packages that extend the functionality of Ruby. Installation of the bundler gem to manage application dependencies

$ gem install bundler

alt text

Installation of Rails

$ gem install rails 

Whenever a new version of Ruby or gem is installed, the rehash sub-command must be run.This will install shims for all Ruby executables known to rbenv, which will allow you to use the executables. In computer programming, a shim is a small library that transparently intercepts API calls and changes the arguments passed, handles the operation itself, or redirects the operation elsewhere.

$ rbenv rehash 

Verify that Rails has been installed properly by printing its version, with this command

$ rails -v

If it installed properly, you will see the version of Rails that was installed.

For one click installation run the rbenv.sh

Run the following command

$ ./rbenv.sh

Running a Sample Ruby Program

Create a file hello.rb

hello.rb

print "Hello, World!\n"

Running the program (hello.rb)

$ ruby hello.rb

The program prints Hello, World!

alt text

INSTALLATION OF RUBY ON RAILS (USING RVM)

INTRODUCTION

Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

Installation Methods

There are several ways to install Ruby:

  • When you are on a UNIX-like operating system, using your system’s package manager is the easiest way of getting started. However, the packaged Ruby version usually is not the newest one.
  • Installers can be used to install a specific or multiple Ruby versions. There is also an installer for Windows.
  • Managers help you to switch between multiple Ruby installations on your system.
  • And finally, you can also build Ruby from source.

Since Ruby on Rails doesn't come in a neatly packaged format, getting the framework installed used to be one of the more difficult parts of getting started. Luckily, tools like rvm, the Ruby Version Manager, have made installation simple.

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

Installing Ruby for Ubuntu 15.04 using Rvm

Installation of dependencies

$ sudo apt-get update
                                                                                                                                                                                    
$ sudo apt-get install -y curl gnupg build-essential                                                                                                                                                                              

alt text alt text curl - Transfers data from or to a server, using one of the protocols: HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE. (To transfer multiple files use wget or FTP.)

gpg — encryption and signing tool

Installation of RVM

$ sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 

$ curl -sSL https://get.rvm.io | sudo bash -s stable
$ sudo usermod -a -G rvm `whoami`

alt text Note: Some systems may need to use gpg2 instead of gpg

The gpg command contacts a public key server and requests a key associated with the given ID. In this case we are requesting the RVM project's key which is used to sign each RVM release. Having the RVM project's public key allows us to verify the legitimacy of the RVM release we will be downloading, which is signed with the matching private key.

alt text

The curl uses the curl web grabbing utility to grab a script file from the rvm website.

alt text

To start using RVM you need to run

$ source /etc/profile.d/rvm.sh

alt text

Note: Run the above command everytime when logged in compulsorily to start the rvm.

Installation of Ruby

To install the latest version

$ rvm install ruby

$ rvm –default use ruby

alt text alt text

To install the Particular Ruby version of Ruby, run:

$ rvm install ruby-X.X.X

$ rvm --default use ruby-X.X.X

For example , consider installation of Ruby version 2.3.1, and setting it as default version with the global sub-command:

$ rvm install ruby-2.3.1

$ rvm –-default use ruby-2.3.1

Installation of Bundler

$ gem install bundler

alt text

Installation of Rails

Rails ships with so many dependencies these days, we're going to need to install a Javascript runtime like NodeJS. This lets you use Coffeescript and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment.

Installation of NodeJS

$ curl -sL https://deb.nodesource.com/setup_4.x | apt-get install      -y nodejs

alt text

Installation of Rails

$ gem install rails -v 5.0.1

alt text

Verify that Rails has been installed properly by printing its version, with this command

$ rails -v

If it installed properly, you will see the version of Rails that was installed.

For one click installation run the rvm.sh

Run the following command

$ ./rvm.sh

Running a Sample Ruby Program

Create a file hello.rb

hello.rb

print "Hello, World!\n"

Running the program (hello.rb)

$ ruby hello.rb

The program prints Hello, World!

alt text

INSTALLATION OF RUBY ON RAILS ( From Source )

INTRODUCTION

Ruby is a powerful, flexible programming language you can use in web/Internet development, to process text, to create games, and as part of the popular Ruby on Rails web framework. Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.

Installation Methods

There are several ways to install Ruby:

  • When you are on a UNIX-like operating system, using your system’s package manager is the easiest way of getting started. However, the packaged Ruby version usually is not the newest one.
  • Installers can be used to install a specific or multiple Ruby versions. There is also an installer for Windows.
  • Managers help you to switch between multiple Ruby installations on your system.
  • And finally, you can also build Ruby from source.

Installing Ruby for Ubuntu 15.04

Install the dependencies required

$ sudo apt-get update

$ sudo apt-get install build-essential

$ sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev  libgdbm3 libgdbm-dev

alt text

alt text

alt text

Downloading ruby

$  wget ftp://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz

alt text

UnZip the Ruby file

$ tar xzvf ruby-2.4.1.tar.gz

alt text

Enter into the downloaded directory.

$ cd ruby-2.4.1

Configure generates the make file and also checks that the server has all of the required dependencies.

$ ./configure

alt text

After that, still in the directory, you need to run the "make" command.

$ make

alt text

This may take a bit longer. Once it finishes, use make install

$ make install  

alt text

Installation of Bundler

$ gem install bundler

alt text

Since ruby package is installed from the source, the gems should already be downloaded. However, they need to be updated.

$ gem update --system

alt text

Installation of Rails

$ gem install rails

alt text

Verify that Rails has been installed properly by printing its version, with this command

$ rails -v

If it installed properly, you will see the version of Rails that was installed.

For one click installation run the source.sh

Run the following command

$ ./source.sh

Running a Sample Ruby Program

Create a file hello.rb

hello.rb

print "Hello, World!\n"

Running the program (hello.rb)

$ ruby hello.rb

The program prints Hello, World!

alt text

Try

Assignment Try

Write a Ruby program to print Hello Ruby! to the console
=begin
Ruby program to print Hello Ruby! to the console 
=end

#printing the string
puts "Hello Ruby!"