Upgrade Ruby in OSX… Eventually…

On 2012/11/15, in osx, rant, webdev, by a b

I’m enjoying learning Ruby.  I recently was doing some fooling around, training, and came across the need for the money gem.

----------------------------
$ gem install money
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into 
      the /Library/Ruby/Gems/1.8 directory.
$

Oh! My bad. I forgot I’m on a new laptop, with the system install of Ruby. No worries, just sudo…

---------------------------- 
$ sudo gem install money
ERROR:  Error installing money:
	money requires Ruby version >= 1.9.2.

$ ruby -v
 ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
$

I didn’t realize I wasn’t on the bleeding edge. No problem, though, because Ruby is magical and it will be snap to upgrade. Just use RVM:

----------------------------
$ rvm install 1.9.3
 No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p286.

 ... blah blah ...

  The provided compiler '/usr/bin/gcc' is LLVM based, it 
  is not yet fully supported by ruby and gems, please 
   read `rvm requirements`.

 ... blah blah ...

 ruby-1.9.2-p320 is not installed.
 To install do: 'rvm install ruby-1.9.3-p286'
$

Right. I thought I just did that, and trying the full suggested version gives the same LLVM compiler problem. I vaguely remember something like this on OSX 10.6, so I guess it’s time to ask the Googz. After not too much poking around, it looks like I can try to install with clang as the C compiler (which is non-LLVM, and should make rvm STFU).

---------------------------- 
$ rvm install ruby-1.9.3-p286 --with-gcc=clang
 Installing Ruby from source to: ~/.rvm/rubies/ruby-1.9.3-p286, 
   this may take a while depending on your cpu(s)...
 1.9.3-p286 - #downloading 1.9.3-p286, 
   this may take a while depending on your connection...

... blah blah blah depending on blah blah ...

Install of 1.9.3-p286 - #complete 
$

Great! It’s complete. Not great, though, because the OSX install of ruby is still linked in ‘/usr/bin’. Weee! Being one to try and follow the way things are already being done, I just want set things up so links in ‘usr/bin’ work, not relink them somewhere else. So, I have to go first to ‘~/.rvm/rubies/’ and link my 1.9.3 build,

----------------------------
$ cd ~/.rvm/rubies/
$ ln -s 1.9.3-p289 1.9.3
$

then go into that folder and for some reason create a ‘usr’ dir with symlink back up to ‘../bin’,

----------------------------
$ mkdir usr; cd usr
$ ln -s ../bin bin

then go to ‘/System/Library/Frameworks/Ruby.framework/Versions’ and get busy with ‘sudo’ and ‘ln’ again so the system path ‘Current’ links to my ‘~/.rvm/rubies/1.9.3’ link.

----------------------------
$ cd /System/Library/Frameworks/Ruby.framework/Versions
$ sudo rm Current
$ sudo ln -s ~/.rvm/rubies/1.9.3  1.9.3
$ sudo ln -s 1.9.3 Current
$ 

Phew. The end result is the rvm install of 1.9.3 linked as ‘Current’, and ‘ruby -v’ returns 1.9.3 as the version. So, back to the original problem, and trying to get money. Mo’ money, forthereals. So I take another crack at it…

----------------------------
$ sudo gem install money
$  ERROR:  Error installing money:
	money requires Ruby version >= 1.9.2.
$

Hoe. Lee. Crap. Looking into it, the problem becomes quickly clear. The symlink to ‘gem’ is still running the OSX install version of 1.8, and ‘ls -l’ confirms this.

$ gem -> ../../System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem

Really? Apple created a ‘Current’ symlink, then ignores that and hard links to the source?. Awesome! After all my ‘do it like they do’ thinking, I actually do have to fix the symlink, anyway:

----------------------------
$ sudo rm gem
$ sudo ln -s ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/gem gem
$

Maybe now ‘sudo gem install money’ will work? Ah… no.

Users/brownlee/.rvm/rubies/ruby-1.9.3-p286
 /lib/ruby/1.9.1/yaml.rb:56:in `':

  It seems your ruby installation is missing psych (for YAML output).
  To eliminate this warning, please install libyaml and reinstall your ruby.

Wow. Ok, now I need to ask Googz again. The solution seems to be ‘rvm pkg install libyaml’. Which is awesome. That also tells me ‘Please note that it’s required to reinstall all rubies: rvm reinstall all –force’. I’m pretty over trying to get anything else done today, so let’s do this. And… of course, that fails, because reinstall falls back to the default gcc, which has LLVM issues. So, trying again with ‘–with-gcc=clang’ added solves that problem. But reinstalling blew away the ‘~/.rvm/rubies/1.9.3/usr/bin’ symlink I made, so I have to fix that to get ‘gem’ working again.

Got all that? Now, after a colossal amount of stupid, I can try ‘sudo gem install money’ one more time.

And it works.

Sweet. Hopefully I can remember what I was working on 3 hours ago, when that who crazy detour started.

 

Comments are closed.