26 September 2017

Ruby - ENVIRONMENT SETUP

Ruby -  ENVIRONMENT SETUP


Try it Option Online
We already have set up Ruby Programming environment online, so that you can
execute almost all the tutorial examples online at the same time when you are
doing your theory work. This gives you confidence in what you are reading and
to check the result with different options. Feel free to modify any example and
execute it online.
Try the following example using the Try it option available on our website at the
top right corner of the sample code box given below:

#!/usr/bin/ruby -w
puts "Hello, Ruby!";

For most of the examples given in this tutorial, you will find a Try it option on
our website code sections at the top right corner that will take you to the online
compiler. So just make use of it and enjoy your learning.

Local Environment Setup
If you are still willing to set up your environment for Ruby programming
language, then let's proceed. This tutorial will teach you all the important topics
related to environment setup. We would recommend you to go through the
following topics first and then proceed further:

Ruby Installation on Linux/Unix

Here are the steps to be followed to install Ruby on a Unix machine:
NOTE: Before proceeding, make sure you have root privilege.

 Download a zipped file having latest version of Ruby. Follow Download
Link.

 After having downloaded the Ruby archive, unpack it and change into the
newly created directory:

$ tar -xvzf ruby-1.6.7.tgz
$ cd ruby-1.6.7

 Now, configure and compile the source code as follows:
$ ./configure
$ make

 Finally, install Ruby interpreter as follows:
$ su -l root # become a root user
$ make install
$ exit # become the original user again

 After installation, make sure everything is working fine by issuing the
following command on the command-line:
$ruby -v
ruby 1.6.7 (2002-06-04) [i386-netbsd]

 If everything is fine, this should output the version of the installed Ruby
interpreter as shown above. You may have installed different version, so it
will display a different version.
Using yum to Install Ruby
If your computer is connected to the Internet, then the easiest way to install
Ruby or any other other RPM is using the yum utility. Give the following
command at the command prompt and you will find Ruby gets installed on your
computer.

$ yum install ruby

Ruby Installation on Windows

Here are the steps to install Ruby on a Windows machine.

NOTE: You may have different versions available at the time of installation.

 Download a zipped file having latest version of Ruby. Follow Download
Link.

 After having downloaded the Ruby archive, unpack it and change into the
newly created directory:

 Double-click the Ruby1.6.7.exe file. The Ruby installation wizard starts.

 Click Next to move to the Important Information page of the wizard and
keep moving till Ruby installer completes installing Ruby.
You may need to set some environment variables if your installation has not
setup them appropriately.

 If you use Windows 9x, add the following lines to your c:\autoexec.bat:
set PATH="D:\(ruby install directory)\bin;%PATH%"

 Windows NT/2000 users need to modify their registries.
o Click Control Panel | System Properties | Environment Variables.
o Under System Variables, select Path and click EDIT.
o Add your Ruby directory to the end of the Variable Value list and click
OK.
o Under System Variables, select PATHEXT and click EDIT.
o Add .RB and .RBW to the Variable Value list and click OK.

 After installation, make sure everything is working fine by issuing the

following command on the command-line:
$ruby -v
ruby 1.6.7

 If everything is fine, this should output the version of the installed Ruby
interpreter as shown above. You may have installed different version, so it
will display a different version.
Ruby Command Line Options
Ruby is generally run from the command line in the following way:

$ ruby [ options ] [.] [ programfile ] [ arguments ... ]

Start typing and press Enter to search