2011-08-11 22:40:36 +02:00
# ruby-build
2015-11-25 20:27:24 +01:00
ruby-build is an [rbenv ](https://github.com/rbenv/rbenv ) plugin that
2013-09-01 14:26:03 +02:00
provides an `rbenv install` command to compile and install different versions
of Ruby on UNIX-like systems.
2011-08-11 22:40:36 +02:00
2013-09-01 14:26:03 +02:00
You can also use ruby-build without rbenv in environments where you need
precise control over Ruby version installation.
2012-05-24 20:33:38 +02:00
2015-11-25 20:27:24 +01:00
See the [list of releases ](https://github.com/rbenv/ruby-build/releases )
2014-04-07 22:17:46 +02:00
for changes in each version.
2012-05-24 20:33:38 +02:00
## Installation
### Installing as an rbenv plugin (recommended)
2013-09-01 14:26:03 +02:00
Installing ruby-build as an rbenv plugin will give you access to the `rbenv
install` command.
2012-05-24 20:33:38 +02:00
2015-11-29 04:02:51 +01:00
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
This will install the latest development version of ruby-build into the
`~/.rbenv/plugins/ruby-build` directory. From that directory, you can check out
a specific release tag. To update ruby-build, run `git pull` to download the
latest changes.
2012-05-24 20:33:38 +02:00
### Installing as a standalone program (advanced)
2013-09-01 14:26:03 +02:00
Installing ruby-build as a standalone program will give you access to the
`ruby-build` command for precise control over Ruby version installation. If you
have rbenv installed, you will also be able to use the `rbenv install` command.
2011-08-11 22:40:36 +02:00
2015-11-29 04:02:51 +01:00
git clone https://github.com/rbenv/ruby-build.git
2012-11-05 17:10:53 +01:00
cd ruby-build
./install.sh
2011-08-11 22:40:36 +02:00
2013-09-01 14:26:03 +02:00
This will install ruby-build into `/usr/local` . If you do not have write
permission to `/usr/local` , you will need to run `sudo ./install.sh` instead.
You can install to a different prefix by setting the `PREFIX` environment
variable.
2011-08-11 22:40:36 +02:00
2013-09-01 14:26:03 +02:00
To update ruby-build after it has been installed, run `git pull` in your cloned
copy of the repository, then re-run the install script.
2012-02-07 21:23:05 +01:00
2012-05-24 20:33:38 +02:00
### Installing with Homebrew (for OS X users)
2012-02-07 21:23:05 +01:00
2013-09-01 14:26:03 +02:00
Mac OS X users can install ruby-build with the [Homebrew ](http://brew.sh )
package manager. This will give you access to the `ruby-build` command. If you
have rbenv installed, you will also be able to use the `rbenv install` command.
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
*This is the recommended method of installation if you installed rbenv with
Homebrew.*
2012-04-21 01:46:02 +02:00
2012-11-05 17:10:53 +01:00
brew install ruby-build
2012-04-21 01:46:02 +02:00
2012-05-24 20:33:38 +02:00
Or, if you would like to install the latest development release:
2012-04-21 01:46:02 +02:00
2012-11-05 17:10:53 +01:00
brew install --HEAD ruby-build
2012-04-21 01:46:02 +02:00
2016-12-05 19:30:46 +01:00
To upgrade the HEAD package use `--fetch-HEAD` option:
2016-09-07 09:02:54 +02:00
2016-12-05 19:30:46 +01:00
brew upgrade --fetch-HEAD ruby-build
2012-04-21 01:46:02 +02:00
2012-05-24 20:33:38 +02:00
## Usage
2014-07-23 23:14:40 +02:00
Before you begin, you should ensure that your build environment has the proper
2015-11-25 20:27:24 +01:00
system dependencies for compiling the wanted Ruby version (see our [recommendations ](https://github.com/rbenv/ruby-build/wiki#suggested-build-environment )).
2014-07-23 23:14:40 +02:00
2012-05-24 20:33:38 +02:00
### Using `rbenv install` with rbenv
2013-09-01 14:26:03 +02:00
To install a Ruby version for use with rbenv, run `rbenv install` with the
exact name of the version you want to install. For example,
2012-05-24 20:33:38 +02:00
2014-12-25 17:06:58 +01:00
rbenv install 2.2.0
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
Ruby versions will be installed into a directory of the same name under
`~/.rbenv/versions` .
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
To see a list of all available Ruby versions, run `rbenv install --list` . You
may also tab-complete available Ruby versions if your rbenv installation is
properly configured.
2012-05-24 20:33:38 +02:00
### Using `ruby-build` standalone
2013-09-01 14:26:03 +02:00
If you have installed ruby-build as a standalone program, you can use the
`ruby-build` command to compile and install Ruby versions into specific
locations.
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
Run the `ruby-build` command with the exact name of the version you want to
install and the full path where you want to install it. For example,
2012-05-24 20:33:38 +02:00
2014-12-25 17:06:58 +01:00
ruby-build 2.2.0 ~/local/ruby-2.2.0
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
To see a list of all available Ruby versions, run `ruby-build --definitions` .
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
Pass the `-v` or `--verbose` flag to `ruby-build` as the first argument to see
what's happening under the hood.
2012-05-24 20:33:38 +02:00
### Custom definitions
2013-09-01 14:26:03 +02:00
Both `rbenv install` and `ruby-build` accept a path to a custom definition file
in place of a version name. Custom definitions let you develop and install
versions of Ruby that are not yet supported by ruby-build.
2012-05-24 20:33:38 +02:00
2013-09-01 14:26:03 +02:00
See the [ruby-build built-in definitions][definitions] as a starting point for
custom definition files.
2015-11-29 04:02:51 +01:00
[definitions]: https://github.com/rbenv/ruby-build/tree/master/share/ruby-build
2012-05-24 20:33:38 +02:00
### Special environment variables
2013-09-01 14:26:03 +02:00
You can set certain environment variables to control the build process.
2012-04-21 01:46:02 +02:00
2012-05-24 20:33:38 +02:00
* `TMPDIR` sets the location where ruby-build stores temporary files.
2013-09-01 14:26:03 +02:00
* `RUBY_BUILD_BUILD_PATH` sets the location in which sources are downloaded and
built. By default, this is a subdirectory of `TMPDIR` .
* `RUBY_BUILD_CACHE_PATH` , if set, specifies a directory to use for caching
downloaded package files.
* `RUBY_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your
choosing.
* `RUBY_BUILD_SKIP_MIRROR` , if set, forces ruby-build to download packages from
their original source URLs instead of using a mirror.
2014-08-17 04:58:43 +02:00
* `RUBY_BUILD_ROOT` overrides the default location from where build definitions
in `share/ruby-build/` are looked up.
2014-08-17 05:01:00 +02:00
* `RUBY_BUILD_DEFINITIONS` can be a list of colon-separated paths that get
additionally searched when looking up build definitions.
2012-05-24 20:33:38 +02:00
* `CC` sets the path to the C compiler.
2013-09-07 00:36:13 +02:00
* `RUBY_CFLAGS` lets you pass additional options to the default `CFLAGS` . Use
this to override, for instance, the `-O3` option.
2012-05-24 20:33:38 +02:00
* `CONFIGURE_OPTS` lets you pass additional options to `./configure` .
2013-09-01 14:26:03 +02:00
* `MAKE` lets you override the command to use for `make` . Useful for specifying
GNU make (`gmake`) on some systems.
* `MAKE_OPTS` (or `MAKEOPTS` ) lets you pass additional options to `make` .
2014-01-22 04:29:02 +01:00
* `MAKE_INSTALL_OPTS` lets you pass additional options to `make install` .
2014-01-22 04:03:33 +01:00
* `RUBY_CONFIGURE_OPTS` , `RUBY_MAKE_OPTS` and `RUBY_MAKE_INSTALL_OPTS` allow
you to specify configure and make options for buildling MRI. These variables
will be passed to Ruby only, not any dependent packages (e.g. libyaml).
2011-08-11 22:40:36 +02:00
2013-12-20 19:06:50 +01:00
### Applying patches to Ruby before compiling
Both `rbenv install` and `ruby-build` support the `--patch` (`-p`) flag that
signals that a patch from stdin should be applied to Ruby, JRuby, or Rubinius
source code before the `./configure` and compilation steps.
Example usage:
```sh
# applying a single patch
$ rbenv install --patch 1.9.3-p429 < /path/to/ruby.patch
# applying a patch from HTTP
$ rbenv install --patch 1.9.3-p429 < < (curl -sSL http://git.io/ruby.patch)
# applying multiple patches
$ cat fix1.patch fix2.patch | rbenv install --patch 1.9.3-p429
```
2012-11-15 23:51:58 +01:00
### Checksum verification
2014-05-23 10:07:14 +02:00
If you have the `shasum` , `openssl` , or `sha256sum` tool installed, ruby-build will
automatically verify the SHA2 checksum of each downloaded package before
2013-09-01 14:26:03 +02:00
installing it.
2012-11-15 23:51:58 +01:00
2013-09-01 14:26:03 +02:00
Checksums are optional and specified as anchors on the package URL in each
definition. (All bundled definitions include checksums.)
2012-11-15 23:51:58 +01:00
### Package download mirrors
2013-09-01 14:26:03 +02:00
ruby-build will first attempt to download package files from a mirror hosted on
Amazon CloudFront. If a package is not available on the mirror, if the mirror
is down, or if the download is corrupt, ruby-build will fall back to the
2013-09-13 13:21:07 +02:00
official URL specified in the definition file.
2012-11-15 23:51:58 +01:00
You can point ruby-build to another mirror by specifying the
2013-09-01 14:26:03 +02:00
`RUBY_BUILD_MIRROR_URL` environment variable--useful if you'd like to run your
own local mirror, for example. Package mirror URLs are constructed by joining
2014-05-23 10:07:14 +02:00
this variable with the SHA2 checksum of the package file.
2012-11-15 23:51:58 +01:00
2014-05-23 10:07:14 +02:00
If you don't have an SHA2 program installed, ruby-build will skip the download
2013-09-01 14:26:03 +02:00
mirror and use official URLs instead. You can force ruby-build to bypass the
mirror by setting the `RUBY_BUILD_SKIP_MIRROR` environment variable.
2012-11-15 23:51:58 +01:00
2012-12-12 20:48:10 +01:00
The official ruby-build download mirror is sponsored by
2015-07-18 08:47:45 +02:00
[Basecamp ](https://basecamp.com/ ).
2012-12-12 20:48:10 +01:00
2012-11-15 23:51:58 +01:00
### Package download caching
2013-09-01 14:26:03 +02:00
You can instruct ruby-build to keep a local cache of downloaded package files
by setting the `RUBY_BUILD_CACHE_PATH` environment variable. When set, package
files will be kept in this directory after the first successful download and
reused by subsequent invocations of `ruby-build` and `rbenv install` .
2012-11-15 23:51:58 +01:00
2013-09-01 14:26:03 +02:00
The `rbenv install` command defaults this path to `~/.rbenv/cache` , so in most
cases you can enable download caching simply by creating that directory.
2012-11-15 23:51:58 +01:00
2012-05-24 20:33:38 +02:00
### Keeping the build directory after installation
2011-08-11 22:40:36 +02:00
2013-09-01 14:26:03 +02:00
Both `ruby-build` and `rbenv install` accept the `-k` or `--keep` flag, which
tells ruby-build to keep the downloaded source after installation. This can be
useful if you need to use `gdb` and `memprof` with Ruby.
2011-08-11 22:40:36 +02:00
2013-09-01 14:26:03 +02:00
Source code will be kept in a parallel directory tree `~/.rbenv/sources` when
using `--keep` with the `rbenv install` command. You should specify the
location of the source code with the `RUBY_BUILD_BUILD_PATH` environment
variable when using `--keep` with `ruby-build` .
2011-08-16 11:31:58 +02:00
2012-05-24 20:33:38 +02:00
## Getting Help
2011-09-14 19:38:34 +02:00
2013-09-01 14:26:03 +02:00
Please see the [ruby-build wiki][wiki] for solutions to common problems.
2015-11-29 04:02:51 +01:00
[wiki]: https://github.com/rbenv/ruby-build/wiki
2011-09-14 19:38:34 +02:00
2012-05-24 20:33:38 +02:00
If you can't find an answer on the wiki, open an issue on the [issue
2015-11-25 20:27:24 +01:00
tracker](https://github.com/rbenv/ruby-build/issues). Be sure to include
2013-09-01 14:26:03 +02:00
the full build log for build failures.