Gem magic – copying gems from a server to your local repository

I recently upgraded to Ubuntu 9.10, wiping everything, formatting my partition and starting again.  There was the usual sunday full of software installing hassles.  But, i discovered one thing that made my life a ton easier, thanks to Marnen Laibow-Koser on http://ruby-forum.com

My situation (a common one) was that i had several apps deployed on servers, and i wanted my development environment to match that of the servers as closely as possible.  This means having the same gems as the servers, and, crucially, having the same versions of those gems.  Normally this would be a big pain in the ass, hunting around for places to get old out of date gems from.  Not so, however – i ssh onto my server and run

gem server & #the & is just to make it run in the background

This starts a gem server running on port 8808.

Now, back in my local machine, i can type

sudo gem install insert-gem-name-here –remote –source http://mywebsite.com:8808

and, hey presto, i get the version that’s on the server, installed locally.  Even better, you can pass it a list of all the gems you need at once, and go and drink a beer to celebrate the utter wonderfulness of rubygems.  Repeat for every app you’re working on, pointing it at it’s relevant server.  Huzzah!

Thanks Marnen!

Advertisements

2 responses to “Gem magic – copying gems from a server to your local repository

  1. I’m glad my advice was helpful. However, as I said on the forum, you really shouldn’t ever need to do this. The only case I can think of where this actually makes sense is if you have proprietary in-house gems that you don’t want to release to the public.

    Otherwise, you should be able to find all gems — even out-of-date versions — on the usual public gem servers. If, as in your case, you’ve forked a gem, then *rename it*, or at least bump the version number, so you don’t defeat the purpose of having gems to begin with.

    Again, I’m glad my suggestion helped. I’m unhappy, though, that it seems to have made it easier for you to abuse the notion of gems in brittle ways.

  2. Hi Marnen

    The gem on my server wasn’t forked, it was unchanged from the one i’d downloaded originally back in the day. This statement “Otherwise, you should be able to find all gems — even out-of-date versions — on the usual public gem servers.” just didn’t seem to be true in this case – i hunted around, adding various repository sites, following various leads on google, and just could not find the version that i was looking for.

    Given that i just wanted a particular version, as it was released originally, is it really abuse to just copy it from somewhere that i own (my server) rather than an official repository, if i can’t find a repository hosting it? It’s the same code after all.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s