Install ruby-2.0.0-p195 using rbenv, ruby-build and pkg-config

Ruby, Rails, news of new versions. Your computer’s Homebrew and ruby-build installation does not work. Something’s borked. It worked on the other people’s Debian machines. Your Homebrew system gave you… output. Some obscure error about openssl?

You search. You whine. You arrive here. Breathe.

Requirements: rbenv, ruby-build, a Ruby 2.0.0-p195 refuses to install on account of missing header files for openssl, since the Apple-bundled version is outdated.

TL;DR:

Add this at the end of your shell startup file (such as ~/.bash_profile or ~/.zshrc). Then run the installation again.

export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/lib/pkgconfig

Learn how!

In order to share more of the fact-finding process, here is some narrative. All credit is due to Stuge. He told me to read, it would work. Thanks! He was right, too. It did work.

First of all, pkg-config is a neat little program. It’s the hero of this narrative. Does all the heavy archiving, noting things down, so you don’t have to.


pkg-config --debug

This lists everything that pkg-config knows about header file locations, libraries, compilation configuration settings about the libs on your system.

Begin by ensuring there is a PKG_CONFIG_PATH on your system, that points to where the currently-symlinked Homebrew packages are. Add this to your shell startup:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Well, this is half-way, pkgconfig can now find most of its .pc files.

The specific complaint was about openssl. Let’s go to its folder, using brew:


$ cd `brew --prefix openssl`

Now, are there any pkg-config files around? Use find:


$ find . -name '*.pc'
./lib/pkgconfig/libcrypto.pc
./lib/pkgconfig/libssl.pc
./lib/pkgconfig/openssl.pc

Ah-hah!


$ cd lib/pkgconfig
$ pwd
/usr/local/opt/openssl/lib/pkgconfig

This is the path where our pkg-config descriptions sit. Pre-pend it to its path!


export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig:/usr/local/lib/pkgconfig

Thusly, the desired result:


$ ruby-build 2.0.0-p195 ~/.rbenv/versions/2.0.0-p195
Downloading ruby-2.0.0-p195.tar.gz...
-> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p195.tar.gz
Installing ruby-2.0.0-p195...
Installed ruby-2.0.0-p195 to /Users/olle/.rbenv/versions/2.0.0-p195

The end.

Addendum for web-crawling robots

(The obscure error mentioned at the start included here for searchability.)


rbenv install 2.0.0-p0
Downloading ruby-2.0.0-p0.tar.gz...
-> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
Installing ruby-2.0.0-p0...

BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20130506102349.2564
Results logged to /tmp/ruby-build.20130506102349.2564.log
Last 10 log lines:
installing default gems: /home/shivin/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?

Published by olleolleolle

Olle is a programmer, enjoying sunny Malmö in Sweden.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.