Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Sourav Moitra edited this page · 109 revisions
Clone this wiki locally

ruby-build is a tool that downloads and compiles various versions of Ruby. It is exposed as rbenv install through rbenv or simply as ruby-build when used standalone.

Suggested build environment

ruby-build will try its best to download and compile the wanted Ruby version, but sometimes compilation fails because of unmet system dependencies, or compilation succeeds but the new Ruby version exhibits weird failures at runtime. The following instructions are our recommendations for a sane build environment.

  • Mac OS X:

    If you haven't done so, install Xcode Command Line Tools (xcode-select --install) and Homebrew. Then:

      # optional, but recommended:
      brew install openssl libyaml libffi
      # required for building Ruby <= 1.9.3-p0:
      brew tap homebrew/dupes && brew install apple-gcc42
  • Ubuntu/Debian/Mint:

    apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
  • CentOS/Fedora 21 and below:

    yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
  • Fedora 22 and above:

    dnf install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
  • openSUSE:

     zypper install gcc automake gdbm-devel libffi-devel libyaml-devel openssl-devel ncurses-devel readline-devel zlib-devel
  • Arch Linux:

    pacman -S base-devel libffi libyaml openssl zlib

    If you're using rbenv:

    • remove --user-install flag from /etc/gemrc.
    • If you get error with readline during the build of ruby, use the RUBY_CONFIGURE_OPTS to specify where to find By example, to install ruby 2.1.1, use the whole following command: RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/" rbenv install 2.1.1.

Updating ruby-build

If you have trouble installing a Ruby version, first try to update ruby-build to get the latest bug fixes and Ruby definitions.

First locate it on your system:

which ruby-build
ls "$(rbenv root)"/plugins

If it's in /usr/local/bin on a Mac, you've probably installed it via Homebrew:

brew upgrade ruby-build

Or, if you have it installed via git as an rbenv plugin:

cd "$(rbenv root)"/plugins/ruby-build && git pull


Missing OpenSSL

The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

You probably need to install openssl development headers:

  • Ubuntu: apt-get install libssl-dev
  • Fedora: yum install openssl-devel

MacPorts users may need to specify OpenSSL's location manually:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/local rbenv install

OpenSSL bindings on Debian

Because of OpenSSL incompatibility in Debian (7.5 and above), Ruby might fail to compile without patching it first:

curl -fsSL | \
  rbenv install --patch 1.9.3-p484

Make error for 2.0.0-p247 (and lower) on Fedora/Red Hat

make[2]: *** [ossl_pkey_ec.o] Error 1

This is a known issue with Ruby's openssl extension. The solution is to apply this patch:

curl -fsSL "" | \
  filterdiff -x a/ChangeLog | rbenv install --patch 2.0.0-p247

Installing 2.0 on OS X 10.9 (Mavericks)

error: C compiler cannot create executables
- or -
fatal error: 'stdlib.h' file not found

You can try installing XCode Command Line tools to get GCC:

  1. xcode-select --install
  2. rbenv install 2.0.0-p247

"mkdir: /Volumes/Macintosh: Not a directory"

This can occur if you have more than one disk drive and your home directory is physically mounted on a volume that might have a space in its name, such as "Macintosh HD":

$ df
/dev/disk2    ...  /
/dev/disk1s2  ...  /Volumes/Macintosh HD

The easiest solution is to avoid building a Ruby version to any path that has space characters in it. So instead of building into ~/.rbenv/versions/<version>, which is the default for rbenv install <version>, instead you could install into /opt/rubies/<version> and symlink /opt/rubies as ~/.rbenv/versions so rbenv continues to work as before:

sudo mkdir -p /opt/rubies
sudo chown "${USER}:staff" /opt/rubies
rm -rf ~/.rbenv/versions                 # This will DELETE your existing Ruby versions!
ln -s /opt/rubies ~/.rbenv/versions

Now proceed as following:

ruby-build <version> /opt/rubies/<version>

1.8.7-p302 (and lower) segfaults for HTTPS requests on OS X 10.7+

Ruby 1.8.7 patchlevel 302 (and below, possibly above, including ruby enterprise edition) have a known compiler bug, however compiling Ruby will finish without errors. The bug will cause a segmentation fault whenever an SSL connection is opened, like .../timeout.rb:60: [BUG] Segmentation fault.

Try setting the following flags and recompiling Ruby:

CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls" rbenv install 1.8.7-p302

Or somehow use gcc 4.6 or earlier instead.

Trouble with irb or pry

Try installing readline and recompiling Ruby.

  • Ubuntu: apt-get install libreadline-dev
  • Fedora: yum install readline-devel
  • Mac OS X with Homebrew:

    brew install readline
    RUBY_CONFIGURE_OPTS=--with-readline-dir="$(brew --prefix readline)" rbenv install 1.9.3-p286

Missing zlib

cannot load such file -- zlib

Try installing zlib and recompiling Ruby.

  • Ubuntu: apt-get install zlib1g-dev
  • Fedora: yum install zlib-devel

Arch Linux default gem install path

WARNING:  You don't have ${HOME}/.gem/ruby/1.8/bin in your PATH,
          gem executables will not run.

The system Ruby creates the /etc/gemrc file which contains --user-install by default so that pacman-managed gems are not mixed up with externally installed gems. This setting affects the gem command in all Ruby versions, so all gems will get installed under ~/.gem instead of the default install path $(rbenv prefix)/lib/ruby/gems.

Missing psych for YAML with Ruby 2.1.0

On *BSD at runtime when you require "yaml" or try to use RubyGems:

It seems your ruby installation is missing psych (for YAML output).
Shared object "" not found, required by ""

If you can, try upgrading to Ruby 2.1.2 where this issue seems to be fixed. If you need to stay on the current version, however, you can work around the issue by setting LD_LIBRARY_PATH in your environment:

LD_LIBRARY_PATH="$(rbenv root)/versions/2.1.0/lib:$LD_LIBRARY_PATH" ruby ...

Build failure of fiddle with Ruby 2.2.0

If you use Debian, Ubuntu, try to install libffi-dev via apt-get.

$ apt-get install libffi-dev

CentOS, Fedora, try to install libffi-devel via yum.

$ yum install libffi-devel

or enabled --enable-shared option

$ RUBY_CONFIGURE_OPTS=--enable-shared rbenv install 2.2.0

No space left on device

Some distributions will mount a tmpfs partition with low disk space to /tmp, such as 250 MB. You can check this with:

mount | grep tmp
df -h | grep tmp

Compiling MRI requires at least 265 MB, so you should temporarily resize /tmp to allow more usage:

rm -rf /tmp/ruby-build*
mount -o remount,size=300M,noatime /tmp

Cannot load such file -- auto_gem on Gentoo

Gentoo defines a system-wide RUBYOPT environment variable that automatically wants to load auto_gem whenever any Ruby scripts gets executed. This will fail for Ruby versions other than the system one.

$ cat /etc/env.d/10rubygems

The solution is to configure your shell init script to export -n RUBYOPT (unexport) the value from your environment.

Reduce parallel jobs

you can get an gcc: internal compiler error: Killed (program cc1) for example at Dreamhost.

The solution is add MAKE_OPT=-j2 to environment variables to limit the make to do parallel jobs at max of 2. Of course, 2 can be other numbers like 1 or 3, 4. By default make will use unlimited jobs it can do.

export MAKE_OPT=-j2

or also with writable temp directory:

TMPDIR=~/tmp MAKE_OPTS=-j2 rbenv install 1.9.3-p327

Build error on gcc < 4.4.0, -Wno-packed-bitfield-compat

For the combination of some versions of ruby (2.2.0, 2.2.3 and maybe others) with a very old version of gcc (less than 4.4.0) you will get an error:

> rbenv install 2.2.3
Downloading ruby-2.2.3.tar.gz...


cc1: error: unrecognized command line option "-Wno-packed-bitfield-compat"

A workaround with ruby-build --patch is:

> cat patch.txt  | rbenv install --patch 2.2.3
Installing ruby-2.2.3...
patching file configure
patching file
Installed ruby-2.2.3 to .../.rbenv/versions/2.2.3

patch.txt can be downloaded at .

Something went wrong with that request. Please try again.