Difference between revisions of "Getting and Installing Ruby"
m (Text replacement - "<<htmlet>" to "<htmlet>") |
m (Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">") |
||
(5 intermediate revisions by the same user not shown) | |||
Line 135: | Line 135: | ||
+ | |||
+ | <htmlet>ezoicbottom</htmlet> | ||
<hr> | <hr> | ||
<table border="0" cellspacing="0" width="100%"> | <table border="0" cellspacing="0" width="100%"> |
Latest revision as of 20:03, 27 October 2016
Previous | Table of Contents | Next |
What is Ruby? | Simple Ruby Examples |
Purchase and download the full PDF and ePub editions of this Ruby eBook for only $8.99 |
No matter how wonderful Ruby is, there isn't much you can do with it if it is not installed on your computer system. In this chapter we will cover the download and installation of Ruby on Linux, UNIX and Windows.
Ruby is itself written in the C programming language. This means that either a binary distribution for your chosen operating system and hardware platform needs to be installed, or the Ruby sources need to be downloaded and compiled on your target system. Whilst compiling Ruby yourself might be fun, it usually makes more sense to simply download and install one of the many pre-built Ruby packages rather than attempt to build your own. In this chapter we will cover installing pre-built Ruby packages on each platform.
Installing Ruby on Linux
There are a number of different Linux distributions available today and it makes sense to install the Ruby package built specifically for your chosen Linux flavor. The best way to do this is to use the standard package manager for that particular Linux.
Ruby on Red Hat Enterprise and Fedora Linux
Red Hat Enterprise Linux and Fedora Linux both use the YUM installation manager and the Red Hat Package Manager (rpm). The first step is to verify if Ruby is already installed. This can be achieved using the following rpm command. In this example, Ruby is not yet installed:
rpm -q ruby package ruby is not installed
If Ruby is not installed, it can be installed using the yum update manager. This needs to be performed as root so the superuser password will be required in the following steps:
su - yum install ruby
The yum tool will locate the ruby package and any other packages on which Ruby is dependent and prompt you to install the packages:
Downloading Packages: (1/2): ruby-1.8.1-7.EL4.8 100% | | 156 kB 00:10 (2/2): ruby-libs-1.8.1-7. 100% | | 1.5 MB 01:23 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: ruby-libs ######################### [1/2] Installing: ruby ######################### [2/2] Installed: ruby.i386 0:1.8.1-7.EL4.8 Dependency Installed: ruby-libs.i386 0:1.8.1-7.EL4.8 Complete!
Once the installation is complete, you may re-run the rpm command to verify the package is now installed:
rpm -q ruby ruby-1.8.1-7.EL4.8
Alternatively, you can verify that Ruby is installed by running it with the command line option to display the version information:
ruby -v ruby 1.8.1 (2003-12-25) [i386-linux-gnu]
Ruby on Ubuntu and Debian Linux
Debian, Ubuntu and other Debian derived Linux distributions use the apt-get tool to manage package installation. If you are running Ubuntu Linux and get the following output from the ruby command, you need to install Ruby:
$ ruby The program 'ruby' is currently not installed. You can install it by typing: sudo apt-get install ruby -bash: ruby: command not found
To install ruby, simply run the apt-get command as instructed in the message:
sudo apt-get install ruby
The apt-get tool will display output listing any other packages required by Ruby (better known as dependencies):
Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libruby1.8 ruby1.8 Suggested packages: ruby1.8-examples rdoc1.8 ri1.8 The following NEW packages will be installed: libruby1.8 ruby ruby1.8 0 upgraded, 3 newly installed, 0 to remove and 135 not upgraded. Need to get 1769kB of archives. After unpacking 6267kB of additional disk space will be used. Do you want to continue [Y/n]?
One the installation process is completed, you can verify that Ruby is installed by running it with the command line option to display the version information:
ruby -v ruby 1.8.1 (2003-12-25) [i386-linux-gnu]
Ruby on Microsoft Windows
To use the One-Click Ruby Installer go to http://rubyforge.org, scroll down to the link to download the One-Click Installer and click on it. A second page will appear listing the various releases of the One-Click Installer. If you are feeling brave, choose the latest Release Candidate. If you prefer something a little more tried and tested, select the last non-release candidate download (for example, ruby186-26.exe).
Once the executable has downloaded, launch it as you would any other Windows application.
There are a number of ways to run Ruby once it is installed. The most basic approach is to start up a Windows Command Prompt and run Ruby from there. For example, we can output the version of Ruby installed on the system as follows:
Another option is to launch the fxri tool from the Windows Start menu. This is an interactive tool which provides access to the Ruby documentation and also the Ruby console for interactively entering Ruby code:
Once you have Ruby installed, it is time to create your first Ruby script which will be covered in the next chapter.
Purchase and download the full PDF and ePub editions of this Ruby eBook for only $8.99 |
Previous | Table of Contents | Next |
What is Ruby? | Simple Ruby Examples |