7oawig
Last Updated: February 25, 2016
·
4.351K
· macfanatic

Setting up a private ruby gems server

I've often thought in the past it would be nice to package something as a gem, but didn't b/c of exposing internal code via ruby gems. However, turns out that it's super simple to setup an internal ruby gems server & use it with your Rails (or any bundler) project.

First, install the Geminabox gem itself on your local computer, and on the server that you want to be the private gem server. Note that the installation instructions for the server are short, but do require making a simple Rack-Sinatra app. On your local computer, you just install the gem.

Start up the server via rack:

$> rackup

On your local computer, configure the gem to point to your private server, an IP address if fine:

$> gem inabox -c
$> http://127.0.0.1:9292

At this point, you should be able to browse the listing of gems on your private server (make sure that you're running a recent version of Sinatra. My server was running 1.0 and I had 500 errors in my Sinatra app. Upgrading to 1.3 fixed the issue). You can also push a gem at this time.

$> cd my_gem
$> bundle exec rake build
$> gem inabox pkg/my_gem-0.1.gem

In your Gemfile that you want to include the gem, just add the private gem server as a source:

$> cat Gemfile
$> source "http://127.0.0.1:9292"
$> gem "my_gem"

Run bundle and you're all set!

NOTE If you want, you can easily set this up via passgener like any other normal Rack based app and then remove the port setting from your Gemfile and re-configure your local gem to use the updated private gem server URL. That's about it!