The first step to get started in Ruby development is setting up your local environment. Due to differences between various operating systems we will cover multiple of them. If you are already able to use a terminal emulator and know how to install Ruby yourself, you can skip this chapter (after you installed Ruby). Otherwise we will guide you through the process of installing Ruby on your computer.
System-wide installation
A common and easy way to install Ruby is to perform a system-wide installation. Depending on the operating system installation procedures will be different (if required at all).
macOS
Ruby comes preinstalled on macOS. To check which version is installed on your system, execute ruby -v
inside a shell session.
If you want to install a more recent version of Ruby, you can:
Linux
On many Linux distributions Ruby is installed by default. To check if Ruby is installed on your system, run ruby -v
in a shell session.
Where this is not the case, or you want to update the installed version, you should use your distribution's package manager. Here we will provide information for some popular Linux distributions here, however it is recommended to users of all distributions to familiarize themselves with their distribution's package manager, since this will allow for the most efficient software management. Whether this is a command-line or graphical application depends on the offerings of the distribution and personal preference of the user.
Debian / Ubuntu
The package manager Synaptic provides graphical package management. It is installed by default under Ubuntu and has to be installed manually on Debian (by running sudo apt-get install synaptic
from the command line).
Instead of using Synaptic you can also use apt directly from the command-line (you can find further information in the Debian Wiki's article on Package Management). Execute sudo apt-get install ruby
from the command line to install Ruby.
Fedora
From the command-line you can install Ruby with DNF by executing sudo dnf install ruby
.
Arch Linux
Use pacman to install Ruby by executing pacman -S ruby
as root.
Mandriva Linux
On Mandriva Linux, install Ruby using the command-line tool urpmi.
PCLinuxOS
On PCLinuxOS, install Ruby using either the graphical tool Synaptic or the command-line tool apt.
Red Hat Linux
On Red Hat Linux, install Ruby using the command-line tool RPM.
Windows
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
require 'xxx'
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
require 'rubygems'
which reverts to typical load behavior.
If you want to speed it up (including rails) you can use
http://github.com/rdp/faster_require
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
If your distro doesn't come with a ruby package or you want to build a specific version of ruby from scratch, please install it by following the directions here. Download from here.
Compile options
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"
Optimizations
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.
Testing Installation
The installation can be tested easily by executing:
$ ruby -v
This should produce an output similar to:
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 an error similar to:
-bash: ruby: command not found
then you did not successfully install Ruby.