Archive | Mac RSS for this section

Import a gemset without bundler

Here’s the scenario…

I’m trying to get a Rails 2.1.1 application up-and-running on my Mac (Lion). The application uses Ruby 1.8.7-p334. Bundler is not used so there’s no chance of doing a bundle install… drat!

I have a gemset export from another developer’s machine, which was created by doing this:

rvm gemset export my_app

That gives me a file which looks like this (truncated for brevity)…

# my_app.gems generated gem export file. Note…
actionmailer -v2.1.1
actionpack -v2.1.1
activerecord -v2.1.1
activeresource -v2.1.1
activesupport -v2.1.1

So, in theory it should be as easy as pie to import this gemset like this:

rvm gemset import my_app

Wrong!

The main problem arises when you install these gems, because the dependencies are not managed properly (this is what bundler was created for). So you end up with multiple versions of gems installed.

Pain.

The trick now is I need to be able to do a diff between my currently installed list of gems and the desired list given to me by the other developer. You could do this manually, but I’m far too lazy for that…

So, I created a little ruby script which will accept two files to be used for the diff operation, together with a third optional argument depending on whether I want to install or remove the gems.

Here’s the script…

#!/usr/bin/env ruby

unless ARGV.count >= 2
  puts "Please provide two files to perform diff..."
  exit
end

def load_file file
  arr = File.readlines(file).map(&:chomp).compact
  arr.shift if arr.first =~ /^#/
  arr
end

f1, f2 = load_file(ARGV[0]), load_file(ARGV[1])
command = ARGV[2] || 'install'

((f1 - f2) + (f2 - f1)).uniq.each do |gem|
  puts "gem #{command} #{gem}"
end

Save this into a file called file_diff.rb and make the file executable:

chmod +x file_diff.rb

Now, it’s easy to get the exact gems installed by following these simple steps…

./file_diff.rb file1 file2 uninstall > uninstall.sh
chmod x+ uninstall.sh
./uninstall.sh

And that’s it! You should now have the same gems in your gemset that your friend has in his gemset, as per his exported list.

Install Ruby 1.8.7 on OSX Lion using RVM

I’ve got a brand spanking new MacBook Pro which is running OS X Lion. I use RVM to manage my Ruby versions. So should you…probably.

Anyway, I needed to install Ruby 1.8.7 for a work application, and although doing this using rvm seems to work, it doesn’t. Although rvm will tell you it’s installed Ruby 1.8.7 cleanly, as soon as you try to install a gem it will blow up in your face with a segmentation fault…

/Users/m/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:60: [BUG] Segmentation fault

Nice.

So after pulling my hair out for the best part of, oh… about 27 minutes, I came across the solution on stackoverflow. Thought I’d just post it here for my own blogging pleasure. Credit to Matt Sanders for the answer:

http://stackoverflow.com/a/7884957

As per Matt’s solution, after you’ve installed Xcode from the App Store, downloaded and installed the OSX gcc installer, run the following to get Ruby 1.8.7 installed cleanly using rvm (adjust the patch level to your own needs):

rvm remove 1.8.7-p334
CC=/usr/bin/gcc-4.2 rvm install 1.8.7-p334 --force

I’m happy now.

Follow

Get every new post delivered to your Inbox.