The Coding Mant.is

Smashing Through Code

RubyGems, Bundler, and Nokogiri — 19-June-2014

RubyGems, Bundler, and Nokogiri

As a part of my latest project, I need to install BOSH-lite (the link to the git repo is in the right navbar).

You would think this would be mostly straightforward, but it was in fact a little painful due to gemhell that I endured. To help save others I am documenting the exact process that I used.

First, after scanning the ReadMe, I saw I’d need Vagrant and Bundler. Thankfully, I have both of those things.

I have my dev-tool-type-stuff in a directory called Development, so I went into the Development directory:

> cd ~/Development

Then I looked at step 3: Clone the repo and run bundler. Cloning the repo was trivial enough:

> git clone https://github.com/cloudfoundry/bosh-lite.git
> cd bosh-lite/

Then came bundler. Ah, god damn it:

> bundle Your Ruby version is 2.0.0, but your Gemfile specified 1.9.3

Ok, I guess I’ll just use rvm to install the appropriate version. Right? Ok, let’s see what I have going on right now.

> rvm Warning! PATH is not properly set up, '/Users/ladyivangrey/.rvm/gems/ruby-2.0.0-p247/bin' is not at first place, usually this is caused by shell initialization files - check them for 'PATH=...' entries, ... [whole bunch more text...]

After some scrolling I see that, in addition to the PATH message, I’m not on the latest version of RVM. No problem. I’ll just install the latest then:

> curl -L https://get.rvm.io | bash -s stable --autolibs=enabled

Pretty painless, right? Before I do anything, let’s make sure the install was sucessful…

> rvm -h A RVM version 1.25.27 (stable) is installed yet 1.25.20 (master) is loaded. Please do one of the following: * 'rvm reload' [More text...]

So I reload RVM. That was painless. The PATH message stays because, well, it isn’t at first place and I don’t feel like changing that right now. (It ends up not mattering.) Ok. Now I can switch to 1.9.3!

> rvm use 1.9.3 ruby-1.9.3-p547 is not installed. To install do: 'rvm install ruby-1.9.3-p547'

Of course it’s not installed. What was I thinking…

> rvm install ruby-1.9.3-p547 Searching for binary rubies, this might take some time. [Some text...] Installing requirements for osx. Updating system....... Error running 'requirements_osx_brew_update_system ruby-1.9.3-p547',  showing last 15 lines of /Users/ladyivangrey/.rvm/log/1403205414_ruby-1.9.3-p547/update_system.log [More text...] ...make sure `brew update` works before continuing.

Ok. I entered brew update, and brew update did in fact work. And I was on the latest version. So I just tried again. Still failed, new error:

> rvm install ruby-1.9.3-p547 Searching for binary rubies, this might take some time. [Some text...] Error running 'requirements_osx_brew_libs_install automake gcc46 libyaml readline openssl' ... [More text...] Try `brew tap --repair` and make sure `brew doctor` looks reasonable. [etc.]

Alright then. I guess that’s a little more helpful.

> brew tap --repair Pruned 0 dead formulae Tapped 145 formulae

Looking good… Next I ran brew doctor. The output was much more lengthy, but not entirely unexpected – it had some standard system stuff and some other stuff from a recent installation of R/RStudio. Amongst the warning messages was one stating that I had MacPorts installed and that it could be causing trouble.

Interestingly, I had actually installed MacPorts a few weeks ago in a failed attempt to install nokogiri for an unrelated Ruby project. This will be relevant later. Not that I know that, mind you. For now, I remove it.

It’s worth mentioning that after removing MacPorts, I was able to install Ruby 1.9.3 (with a message informing me that it is no longer maintained as of Feb 2014). I was able to successfully switch to 1.9.3. Now all I have to do is run bundle, right?

> rvm use 1.9.3 > bundle

Ahahaha I am so naive.

An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

I see nokogiri and feel flashbacks involving pain and dependencies.

You see, back a few weeks ago I had tried installing nokogiri for a different project. I tried using the instructions for Home Brew (v0.9.5), since I already had it installed, to no avail. Then I installed and tried Mac Ports. Also to no avail. It’s worth mentioning that I was never actually able to install nokogiri, I just looped around in dependency hell for a couple hours before finding a way to not need it. Which is why I’m in this mess now (again). First I try the direct approach:

> gem install nokogiri -v '1.6.2.1' [Some text...] libiconv is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies. [^ this is the same issue I had before, of course...] [...more text...]

I don’t really feel like re-installing MacPorts. Partly because I literally just removed it and haven’t needed it since the previous nokogiri debacle, and partly because I didn’t even get nokogiri successfully installed last time anyway. So I decide to plow ahead pulling up same instructions as last time. The results were the same (surprise?):

> brew install libxml2 libxslt brew: Right on. > brew link libxml2 libxslt brew: LOL > brew link --force libxml2 libxslt brew: ROFL > sudo brew link libxml2 libxslt brew: ROTFLMAO > fuck you brew -bash: fuck: command not found

Ok. It didn’t really go like that. But I was frustrated. It installed libxml2 & libxslt, which is needed per the nokogiri installation instructions, but when I tried to link them I received a message that I needed to use –force. So I tried that, still apparently naive in thinking that these damn outputs will actually help me. That time I received a permissions error, so I figured I’d try sudo, but I just got this:

Error: Cowardly refusing to `sudo brew link`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so 
at your own risk.

Then came Google. I searched around to see who had successfully managed to get nokogiri on a system running OS 10.9.x (disclosure: I currently have 10.9.3). Some had success installing just libiconv, but that didn’t work for me because I apparently don’t have apple-gcc42.

F.
M.
L.

Not having learned my lesson yet, I try installing apple-gcc42. Which of course fails.

So I decided to try a new approach. Again.

Then after much more googling, I found someone who happened to do the install with Xcode. I already have the latest version of Xcode on my machine (v5.1.1 as of the time of this writing), so I figured why not?

(What is this I’m feeling… is it… hope?)

> gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
[Some text...]
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.
[More text...]
libiconv is missing.  please visit 
http://nokogiri.org/tutorials/installing_nokogiri.html for 
help with installing dependencies.
[Additional text...]

Nope. Just sweat, shame, and tears. God damn it nokogiri, why must you do this to me. What did I ever do to you?

It is around this point that I decide that everyone involved with bundler, rubygems, and nokogiri should be forced to eat salad. This may not make a lot of sense, but I happen to despise salad (while simultaneously enjoying an otherwise wide variety of produce, just not leafy greens).

Upon further investigation, someone on Stack Overflow mentioned that the above worked, but only after they ran xcode-select –install. So hey, what the hell. Let’s give that a go to:

> xcode-select --install
[No errors - but there is a pop up to accept a licensing agreement/Apple TOS]
> gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
[Some text... no errors...]
[...Maybe this is hope?]
Successfully installed nokogiri-1.6.2.1
Installing ri documentation for nokogiri-1.6.2.1
1 gem installed

Holy. shit.

It installed.

IT INSTALLED!

IT INSTALLED!

So now I try bundle again, and bundle runs without complaint.

I never knew I could experience happiness and Ruby dependencies at the same time. This is a foreign experience. Perhaps… perhaps a repeatable one.

Haha nah. We’ll see what happens the next time I involve myself with Ruby before I make that call.

The rest of the vagrant stuff will hopefully go through without a hitch so I can work on figuring out how to use bosh-lite.

Update 6/20: I never learn.

Summary – How I installed Nokogiri on OS 10.9.x

Since there’s a lot of pain going on up there, I figured it may be helpful to separate out how exactly I was finally able to install nokogiri on OS 10.9.x.

  1. Make sure you have Xcode installed
    Note: This can be done in the AppStore. As of right now I have 5.1.1, so I can’t vouch for the effectiveness of other versions.
  2. Enter the following in terminal:
    xcode-select --install
  3. Accept/Agree with the Licensing agreement/TOS that pops up (unless you don’t want to install the tools of course).
    Note: This will be a pop up, it is not in the command line.
  4. Enter the following in terminal:
    gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2

Hope someone finds this useful :)

Update 12/15/2014: I also had success installing nokogiri using the above method on OS 10.10.1

Design a site like this with WordPress.com
Get started