Before we proceed practically, it is important to have an up-to-date environment. This tutorial will teach you all the important topics related to environment setup. I would recommend to go through the following topics first and then proceed further:
- Ruby Installation on Unix : If you are planning to have your development environment on Unix Machine then go through this chapter.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 easiest way to install ruby or any other other RPM is using yum utility. Give following command at command prompt and you will find ruby gets installed on your computer.$ yum install ruby
- Ruby Installation on Windows : If you are planning to have your development environment on Windows Machine then go through this chapter.Here are the steps to install Ruby on a Windows machine.NOTE: You may have different version 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 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.
- Click Control Panel | System Properties | Environment Variables.
- Under System Variables, select Path and click EDIT.
- Add your Ruby directory to the end of the Variable Value list and click OK.
- Under System Variables, select PATHEXT and click EDIT.
- 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 : This chapter list out all the command line options which you can use along with Ruby interpreter.NOTE: You may have different version 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 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.
- Click Control Panel | System Properties | Environment Variables.
- Under System Variables, select Path and click EDIT.
- Add your Ruby directory to the end of the Variable Value list and click OK.
- Under System Variables, select PATHEXT and click EDIT.
- 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 Environment Variables : This chapter has a list of all the important environment variables to be set to make Ruby Interpreter works.Ruby interpreter uses the following environment variables to control its behavior. The ENV object contains a list of all the current environment variables set.
Variable Description DLN_LIBRARY_PATH Search path for dynamically loaded modules. HOME Directory moved to when no argument is passed to Dir::chdir. Also used by File::expand_path to expand "~". LOGDIR Directory moved to when no arguments are passed to Dir::chdir and environment variable HOME isn't set. PATH Search path for executing subprocesses and searching for Ruby programs with the -S option. Separate each path with a colon (semicolon in DOS and Windows). RUBYLIB Search path for libraries. Separate each path with a colon (semicolon in DOS and Windows). RUBYLIB_PREFIX Used to modify the RUBYLIB search path by replacing prefix of library path1 with path2 using the format path1;path2 or path1path2. RUBYOPT Command-line options passed to Ruby interpreter. Ignored in taint mode (Where $SAFE is greater than 0). RUBYPATH With -S option, search path for Ruby programs. Takes precedence over PATH. Ignored in taint mode (where $SAFE is greater than 0). RUBYSHELL Specifies shell for spawned processes. If not set, SHELL or COMSPEC are checked. For Unix use env command to see a list of all environment variables.HOSTNAME=ip-72-167-112-17.ip.secureserver.net RUBYPATH=/usr/bin SHELL=/bin/bash TERM=xterm HISTSIZE=1000 SSH_CLIENT=122.169.131.179 1742 22 SSH_TTY=/dev/pts/1 USER=amrood JRE_HOME=/usr/java/jdk/jre J2RE_HOME=/usr/java/jdk/jre PATH=/usr/local/bin:/bin:/usr/bin:/home/guest/bin MAIL=/var/spool/mail/guest PWD=/home/amrood INPUTRC=/etc/inputrc JAVA_HOME=/usr/java/jdk LANG=C HOME=/root SHLVL=2 JDK_HOME=/usr/java/jdk LOGDIR=/usr/log/ruby LOGNAME=amrood SSH_CONNECTION=122.169.131.179 1742 72.167.112.17 22 LESSOPEN=|/usr/bin/lesspipe.sh %s RUBYLIB=/usr/lib/ruby G_BROKEN_FILENAMES=1 _=/bin/env
Popular Ruby Editors:
To write your Ruby programs you will need an editor:
- If you are working on Windows machine then you can use any simple text editor like Notepad or Edit plus.
- VIM (Vi IMproved) is very simple text editor. This is available on almost all Unix machines and now Windows as well. Otherwise your can use your favorite vi editor to write Ruby programs.
- RubyWin is a Ruby Integrated Development Environment (IDE) for Windows.
- Ruby Development Environment (RDE) is also very good IDE for windows users.
Interactive Ruby (IRb):
Interactive Ruby (IRb) provides a shell for experimentation. Within the IRb shell, you can immediately view expression results, line by line.
This tool comes along with Ruby installation so you have nothing to do extra to have IRb working.
Just type irb at your command prompt and an Interactive Ruby Session will start as given below:
$irb irb 0.6.1(99/09/16) irb(main):001:0> def hello irb(main):002:1> out = "Hello World" irb(main):003:1> puts out irb(main):004:1> end nil irb(main):005:0> hello Hello World nil irb(main):006:0> |
Nice post ! Thanks for sharing valuable information with us. Keep sharing.. Ruby on Rails Online Course Hyderabad
ReplyDeleteThis comment has been removed by the author.
ReplyDelete