Building Ruby 2.0.0 and 2.1.1 on OS X

For some reason today I needed to install both Ruby 2.0.0-p451 and 2.1.1 on OS X Mavericks, using rbenv. Unfortunately, if you have Homebrew’s readline package installed (which if you are like me, you probably do, as quite a few other packages depend on it), then there is a conflict that causes a build failure.

Patches

Fortunately, Juan Azambuja pointed out that Arne Brasseur had working patches for 2.0.0-p451 and 2.1.1. These are patches to Ruby itself, and I had to figure out how to apply them while installing.

This actually is not too difficult, as rbenv install --patch <version> will accept a patch from stdin and apply it while building. Juan’s patches, however, will throw a bit of a hiccup as the file paths are prefixed with orig/ and fixed/ (because he diffed between two repos), and the application will ask for the correct paths (without the prefixes). This is not a huge deal, but I have some updated gists that prevent it, for 2.0.0-p451 and 2.1.1. You just have to download the patches and send them to stdin when installing.

Downloading the patch

Well this is what curl is useful for, given a link, it will download the contents at the specified URL and output them to stdout. I’m sure wget would work fine here too. For more info, see man curl.

Piping from stdout to stdin

Notice that curl puts the contents it got to its own stdout, but rbenv install --patch wants to get the patch from stdin; this redirection is exactly what shell pipes are for, taking one process’s stdout and piping it to another’s stdin, hence: curl <ULR> | rbenv install --patch <version>.

TL;DR

curl https://gist.githubusercontent.com/andschwa/11334509/raw/f5e459aefafb0e48c62e04ff7da582093fb35233/ruby-2.0-p451-readline.patch | rbenv install --patch 2.0.0-p451
curl https://gist.githubusercontent.com/andschwa/11334511/raw/563d5c2efb869cafb0c65404d12243822bba2817/ruby-2.1.1-readline.patch | rbenv install --patch 2.1.1