Creating a Simple Private Gem Repository

October 8, 2008 | code, ruby

I recently wanted to create a simple local gem repository. Not all of the gems we write are relevant to the world at large, so github or rubyforge are not great solutions for hosting them.

You can use the gem server command, but if you already have an apache HTTP server somewhere, incredibly easy to get a private gem repository going, server why not use that?

1. Copy the .gem file to your server

scp your.gem your.server:/your/gem/path

2. Create a folder for hosting your gems on the server

ssh user@your.server
cd /var/www/html
mkdir my_awesome_gems
cd my_awesome_gems
mkdir gems
cp /your/gem/path/*.gem ./gems

3. Generate the gem index
gem comes with a command generate_index which generates all of the files necessary for serving gems over HTTP.

cd /var/www/html/my_awesome_gems
gem generate_index

At this point you should be able to access http://your.server/my_awesome_gems/ and see file listings.

4. Add your new source and install your gem on your client

sudo gem sources -a http://your.server/my_awesome_gems/

You should be able to install your gems from this repository now!

sudo gem install [your gem]

That’s it, you’re now stashing gems in your own repo!

Post a Comment