From Gentoo Wiki
Jump to:navigation Jump to:search

Ruby is an interpreted programming language. An implementation of the Ruby interpreter is required for software like Rails, passenger, and GitLab.


USE flags

USE flags for dev-lang/ruby An object-oriented scripting language

berkdb Add support for sys-libs/db (Berkeley DB for MySQL)
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
examples Install examples, usually source code
gdbm Add support for sys-libs/gdbm (GNU database libraries)
ipv6 Add support for IP version 6
jemalloc Use dev-libs/jemalloc for memory management
jit Enable just-in-time compilation for improved performance. May prevent use of some PaX memory protection features in Gentoo Hardened.
rdoc Install dev-ruby/rdoc after installing Ruby.
socks5 Add support for the socks5 proxy
ssl Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
static-libs Build static versions of dynamic libraries as well
systemtap Enable SystemTAP/DTrace tracing
tk Add support for Tk GUI toolkit
valgrind Enable annotations for accuracy. May slow down runtime slightly. Safe to use even if not currently using dev-debug/valgrind
xemacs Add support for XEmacs


Emerge the base package:

root #emerge --ask dev-lang/ruby
Adding the base package in this way will pull it into the system's @world set. Those who are not developing Ruby packages or have some clear and explicit reason for directly emerging the package should gather additional information before proceeding.

Adding a new implementation

To add a new implementation, first adjust the Ruby target variable in /etc/portage/make.conf. For example, if upgrading from Ruby 2.5 to Ruby 2.6, add ruby26 to the RUBY_TARGETS variable:

FILE /etc/portage/make.conf
# 2020-04-05 upgrade from ruby 2.5 to ruby 2.6 -Larry
# RUBY_TARGETS="ruby25"
RUBY_TARGETS="ruby25 ruby26"

Next perform an upgrade of the Ruby base package:

root #emerge --ask --oneshot --update dev-lang/ruby

List then select the newly installed implementation using eselect:

root #eselect ruby list
Available Ruby profiles:
  [1]   ruby25 (with Rubygems) *
  [2]   ruby26 (with Rubygems)
root #eselect ruby set ruby26
Successfully switched to profile:

Finally, update the rest of the packages on the system. This will avoid certain bugs[1] that require the newly emerged Ruby implementation to be selected before upgrading. It will force all packages that depend on and support the Ruby 2.6 base implementation to rebuilt:

root #emerge --ask --update --deep --newuse @world

Once all packages depending on the newly installed implementation have been rebuilt, the older implementation can be unmerged (uninstalled). For removal instructions the Removal section below.

Installing a test implementation

Starting with Ruby 2.2 the Gentoo Ruby project is using the stable mask mechanism to keep new Ruby implementations marked as testing until they are ready to be unmasked. For example, to use Ruby 2.7 on an otherwise stable system, apply the following changes:

FILE /etc/portage/profile/use.stable.maskUnmasking flags for Ruby 2.7

For further information please see the similar instructions for Python.



Activate a specific Ruby implementations by adding RUBY_TARGETS="$implementation" to /etc/portage/make.conf. Please note: setting the RUBY_TARGETS variable may overwrite the implementations set by the systems base profile.

FILE /etc/portage/make.conf
RUBY_TARGETS="ruby25 ruby26 ruby27"

Multiple Ruby implementations in can be installed in parallel. The RUBY_TARGETS variable picks the implementations from USE_RUBY (which is set ebuilds depending on Ruby) and (re)compiles packages with support for each selected implementation.

Select a Ruby slot with eselect

Ruby is slotted in Portage, to view which installed version slot the system is currently using, run:

root #eselect ruby list

To change the selected slot, issue:

root #eselect ruby set ruby26


Package fails to emerge due to missing Ruby target(s)

When a world update fails due to missing a Ruby target, emerge will show the following output:

 * You need to select at least one compatible Ruby installation target via RUBY_TARGETS in make.conf.
 * Compatible targets for this package are: ruby26
 * ruby27
 * See for more information.
 * ERROR: app-misc/hivex-1.3.20::gentoo failed (prepare phase):
 *   No compatible Ruby target selected.
 * Call stack:
 *, line  127:  Called src_prepare
 *   environment, line 3475:  Called ruby-ng_src_prepare
 *   environment, line 3224:  Called _ruby_each_implementation '_ruby_source_copy'
 *   environment, line  939:  Called die
 * The specific snippet of code:
 *           die "No compatible Ruby target selected.";

To fix the issue, add the target(s) displayed above into the RUBY_TARGETS variable in Portage's /etc/portage/make.conf file and re-run previously failed emerge command. See the make.conf section above.


Removing an old implementation

To remove an old implementation, in this case Ruby 2.4, first be certain Ruby has been updated (see the Adding a new implementation section). A newer implementation of Ruby will need to be installed before an older implementation can be removed. This is to ensure the packages that depend on Ruby will have an interpreter with which to run.

After the new implementation has been selected, remove the old implementation from the RUBY_TARGETS variable:

FILE /etc/portage/make.confRemoving the Ruby 2.4 implementation
# RUBY_TARGETS="ruby24 ruby25" # 2020-04-05 removed ruby24 -Larry

It is safe not to add and remove targets to the RUBY_TARGETS variable in one step.

Next, ask Portage to rebuild the @world set with the new Ruby target list:

root #emerge --ask --update --deep --newuse @world

After the emerge completes, update the slot to the newly installed version (2.5 in this case) using eselect as mentioned above.

Finally, as long as no packages are still using the old version, it should be removable by asking Portage to do a dependency clean:

root #emerge --depclean

See also

  • Python — an extremely popular cross-platform object oriented programming language.
  • Project:Ruby
  • Gem — programs and libraries for the Ruby programming language.

External resources