Related Topics
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 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 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 the 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
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
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
If bash: git: command not found error arises
Install git
$ sudo apt-get install git
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
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
}
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
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
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
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!
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
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`
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.
The curl uses the curl web grabbing utility to grab a script file from the rvm website.
To start using RVM you need to run
$ source /etc/profile.d/rvm.sh
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
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
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
Installation of Rails
$ gem install rails -v 5.0.1
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!
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 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 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 the 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
Downloading ruby
$ wget ftp://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz
UnZip the Ruby file
$ tar xzvf ruby-2.4.1.tar.gz
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
After that, still in the directory, you need to run the "make" command.
$ make
This may take a bit longer. Once it finishes, use make install
$ make install
Installation of Bundler
$ gem install bundler
Since ruby package is installed from the source, the gems should already be downloaded. However, they need to be updated.
$ gem update --system
Installation of Rails
$ gem install rails
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