Ruby Programming/Installing Ruby
To find the easiest way to install Ruby for your system, follow the directions below. You can also install Ruby by compiling the source code, which can be downloaded from the Ruby web site.
- 1 Operating systems
- 2 Building from Source
- 3 Compile options
- 4 Testing Installation
- 5 References
Mac OS X
Ruby comes preinstalled on Mac OS X. To check what version is on your system:
- Launch the Terminal application, which is located in the "Utilities" folder, under "Applications".
- At the command-line, enter:
If you want to install a more recent version of Ruby, you can:
- Buy the latest version of Mac OS X, which may have a more recent version of Ruby.
- Install Ruby using RVM. (This is the most popular way because you can manage ruby versions and install many other ruby packages)
- Install Ruby using Fink.
- Install Ruby using MacPorts.
- Install Ruby using Homebrew.
Ruby comes preinstalled on many Linux systems. To check if Ruby is installed on your system, from the shell run:
If ruby is not installed, or if you want to upgrade to the latest version, you can usually install Ruby from your distribution's software repository. Directions for some distributions are described below.
Debian / Ubuntu
On PCLinuxOS, install Ruby using either the graphical tool Synaptic or the command-line tool apt.
Red Hat Linux
Ruby does not come preinstalled with any version of Microsoft Windows. However, there are several ways to install Ruby on Windows.
- Download and install one of the compiled Ruby binaries from the Ruby web site.
- Download and run the one click RubyInstaller.
- Install Cygwin, a collection of free software tools available for Windows. During the install, make sure that you select the "ruby" package, located in the "Devel, Interpreters" category.
Windows is slow
Currently Ruby on windows is a bit slow. Ruby isn't optimized for windows, because most core developers use Linux. Though 1.9.2 passes almost all core tests on windows.
Most of today's slowdown is because when ruby does a
it searches over its entire load path, looking for a file named xxx, or named xxx.rb, or xxx.so or what not. In windows, doing file stat's like that are expensive, so requires take a longer time in windows than linux. 1.9 further complicates the slowdown problem by introducing gem_prelude, which avoids loading full rubygems (a nice speedup actually), but makes the load path larger, so doing require's on windows now takes forever. To avoid this in 1.9.2, you can do a
which reverts to typical load behavior.
If you want to speed it up (including rails) you can use
Which have some work arounds to make loading faster by caching file locations.
Also the "rubyinstaller" (mingw) builds are faster than the old "one click" installers If yours comes from rubyinstaller.org, chances are you are good there.
NB that Jruby tends to run faster but start slower, on windows, than its MRI cousins. Rubinius is currently not yet windows compatible.
Building from Source
Building with debug symbols
If you want to install it with debug symbols built in (and are using gcc--so either Linux, cygwin, or mingw).
./configure --enable-shared optflags="-O0" debugflags="-g3 -ggdb"
Note that with 1.9 you can pass it
--disable-install-doc to have it build faster.
To set the GC to not run as frequently (which tends to provide a faster experience for larger programs, like rdoc and rails), precede your build with
$ export CCFLAGS=-DGC_MALLOC_LIMIT=80000000
though you might be able to alternately put those in as opt or debug flags, as well.
The installation can be tested easily.
$ ruby -v
This should return something like the following:
ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
If this shows up, then you have successfully installed Ruby. However, if you get something like the following:
-bash: ruby: command not found
Then you did not successfully install Ruby.