With package managers or third-party tools, you have plenty of optionsto install and manage Ruby.
You may already have Ruby installed on your computer. You can checkinside aterminal emulator by typing:
ruby-v
This should output some information on the installed Ruby version.
There are several ways to install Ruby:
On Windows 10, you can also use theWindows Subsystem for Linuxto install one of the supported Linux distributions and use any of theinstallation methods available on that system.
Here are available installation methods:
If you cannot compile your own Ruby, and you do not want to use athird-party tool, you can use your system’s package manager to install Ruby.
Some members of the Ruby community feel that you should avoid packagemanagers to install Ruby and that you should use dedicated tools instead.
It is possible that major package managers will install older Rubyversions instead of the latest release. To use the latest Ruby release,check that the package name matches its version number. Or use adedicatedinstaller.
Debian GNU/Linux and Ubuntu use the apt package manager. You can use itlike this:
$sudoapt-getinstallruby-full
CentOS, Fedora, and RHEL use the yum package manager.You can use it like this:
$sudoyuminstallruby
The installed version is typically the latest version of Ruby availableat the release time of the specific distribution version.
Snap is a package manager developed by Canonical.It is available out-of-the-box on Ubuntu, but snap also workson many other Linux distributions.You can use it like this:
$sudosnapinstallruby--classic
We have several channels per Ruby minor series.For instance, the following commands switch to Ruby 2.3:
$sudosnap switch ruby--channel=2.3/stable$ sudosnap refresh
Gentoo uses the portage package manager.
$sudoemerge dev-lang/ruby
To install a specific version, setRUBY_TARGETS
in yourmake.conf
.See theGentoo Ruby Project website for details.
Arch Linux uses a package manager named pacman.To get Ruby, just do this:
$sudopacman-S ruby
This should install the latest stable Ruby version.
Ruby versions 2.0 and above are included by default in macOS releasessince at least El Capitan (10.11).
Homebrew is a commonly used package manager on macOS.Installing Ruby using Homebrew is easy:
$brewinstallruby
This should install the latest Ruby version.
FreeBSD offers both pre-packaged and source-based methods to install Ruby.Prebuilt packages can be installed via the pkg tool:
$pkginstallruby
A source-based method can be used to install Ruby using thePorts Collection. This is useful if you wantto customize the build configuration options.
More information about Ruby and its surrounding ecosystem on FreeBSDcan be found on theFreeBSD Ruby Project website.
OpenBSD as well as its distribution adJ has packages for the threemajor versions of Ruby. The following command allows you to see theavailable versions and to install one:
$doas pkg_add ruby
You can install multiple major versions side by side, because theirbinaries have different names (e.g.ruby27
,ruby26
).
TheHEAD
branch of the OpenBSD ports collection might have themost recent version of Ruby for this platform some days after itis released, seedirectory lang/ruby in the most recent ports collection.
To install Ruby onOpenIndiana, please use theImage Packaging System (IPS) client.This will install the Ruby binaries and RubyGems directlyfrom the OpenIndiana repositories. It’s easy:
$pkginstallruntime/ruby
However, the third-party tools might be a good way to obtain thelatest version of Ruby.
On Windows, you can use theWindows Package Manager CLIto install Ruby:
> winget install RubyInstallerTeam.Ruby.{MAJOR}.{MINOR}# Example> winget install RubyInstallerTeam.Ruby.3.2# To see all versions available> winget search RubyInstallerTeam.Ruby# Note: if you are installing ruby for projects, you may want to install RubyWithDevKit> winget install RubyInstallerTeam.RubyWithDevKit.3.2
Also on Windows, you can use theChocolatey Package Managerto install Ruby:
> chocoinstallruby
It will reuse existingmsys2
, or install own for complete Ruby development environment
On other systems, you can search the package repository of your Linuxdistribution’s manager for Ruby. Alternatively, you can use athird-party installer.
If the version of Ruby provided by your system or package manager is outof date, a newer one can be installed using a third-party installer.
Some installers allow you to install multiple versions on the samesystem; associated managers can help to switch between the differentRubies.
If you are planning to useRVM as a version manager you don’tneed a separate installer, it comes with its own.
ruby-build is a plugin forrbenv that allows youto compile and install different versions of Ruby. ruby-build can alsobe used as a standalone program without rbenv. It is available for macOS,Linux, and other UNIX-like operating systems.
ruby-install allows you to compile and install differentversions of Ruby into arbitrary directories.chruby is acomplimentary tool used to switch between Ruby versions. It is availablefor macOS, Linux, and other UNIX-like operating systems.
On Windows,RubyInstaller gives you everything you needto set up a full Ruby development environment.
Just download it, run it, and you are done!
If you are installing Ruby in order to use Ruby on Rails,you can use the following installer:
Many Rubyists use Ruby managers to manage multiple Rubies. They alloweasy or even automatic switching between Ruby versions depending on theproject and other advantages but are not officially supported. You canhowever find support within their respective communities.
asdf-vm is an extendable version manager that can manage multiplelanguage runtime versions on a per-project basis. You will need theasdf-ruby plugin (which in turn usesruby-build)to install Ruby.
chruby allows you to switch between multiple Rubies. It canmanage Rubies installed byruby-install or even builtfrom source.
mise-en-place allows you to switch between multiple Rubies without requiring additional tools.It manages installations automatically and includes agem backend to manage versions of CLIs written in Ruby.It supports UNIX-like and Windows operating systems.
rbenv allows you to manage multiple installations of Ruby.While it can’t install Ruby by default, itsruby-buildplugin can. Both tools are available for macOS, Linux, or otherUNIX-like operating systems.
rbenv for Windows allows you to install andmanage multiple installations of Ruby on Windows. It’s written inPowerShell thus providing a native way to use Ruby for Windows users.Besides, the command line interface is compatible withrbenvon UNIX-like systems.
RVM allows you to install and manage multiple installations ofRuby on your system. It can also manage different gemsets. It isavailable for macOS, Linux, or other UNIX-like operating systems.
RVM 4 Windows allows you to install and manage multipleinstallations of Ruby on Windows. It is a clone of the original RVM andsupports the classic command line as well as Powershell by providingthe same command line interface as the original RVM.
Uru is a lightweight, multi-platform command line tool that helps youto use multiple Rubies on macOS, Linux, or Windows systems.
Of course, you can install Ruby from source.Download and unpack a tarball, then just do this:
$./configure$make$sudomakeinstall
By default, this will install Ruby into/usr/local
.To change, pass the--prefix=DIR
option to the./configure
script.
You can find more information about building from source in theBuilding Ruby instructions.
Using the third-party tools or package managers might be a better idea,though, because the installed Ruby won’t be managed by any tools.