Skip to content
This repository

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
    
      # required for building Ruby <= 1.9.3-p0:
      brew tap homebrew/dupes && brew install apple-gcc42
    
  • Ubuntu/Debian:

    apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev
    
  • CentOS/Fedora:

    yum install gcc-c++ glibc-headers openssl-devel readline libyaml-devel readline-devel zlib zlib-devel
    
  • Arch Linux:

    pacman -S gcc zlib readline autoconf make
    

    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 libreadline.so. By example, to install ruby 2.1.1, use the whole following command: RUBY_CONFIGURE_OPTS=--with-readline-dir="/usr/lib/libreadline.so" 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

Troubleshooting

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

OpenSSL bindings on Debian 8.0 "jessie"

Because of OpenSSL incompatibility in Debian "jessie", Ruby might fail to compile without patching it first:

curl -fsSL https://github.com/ruby/ruby/commit/1e7a929c1d44d7a368fbe379211183ac6c972920.patch | \
  filterdiff --strip=1 -i a/ext/openssl/ossl_ssl.c | rbenv install -p 1.9.3-p484

filterdiff is a program found in "patchutils".

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 https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/diff?format=diff | filterdiff -x 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

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

Ruby 1.8.7 patchlevel 302 (and below) has a known compiler bug, however compiling Ruby will finish without errors. The bug will cause a segmentation fault whenever an SSL connection is opened.

Try setting the following flags and recompiling Ruby:

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

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

It seems your ruby installation is missing psych (for YAML output).

Try installing libyaml and recompiling Ruby.

See #119 for background.

Something went wrong with that request. Please try again.