Well, we all depend of free and open-source projects, but sometimes you just
cant't share your work.

Here I'll show to you the necessary steps to get your private gem server up and

First of all, install geminabox gem. (thanks to Tom Lea)

$ gem install geminabox

Create a directory for storing gems:

$ mkdir data

Create a rackup file ( file containing the following code:

require "rubygems"  
require "geminabox" = "./data"  
run Geminabox  

Here you are already able to run rackup command via terminal and
start uploading gems (gem inabox myprivategem-1.0.0.gem) and see
the web interface of geminabox. But before that we should setup some HTTP
Basic Authentication for your server.

I'm using a simple Nginx reverse-proxy for a single Thin instance.

Create a new file at your nginx's 'sites-enabled' directory. With the following
configuration. I'll name it 'gemserver'. (/etc/nginx/sites-enabled/gemserver)

upstream gem_server {  
    server fail_timeout=0;

server {  
    listen 80;
    client_max_body_size 20M;

    client_header_timeout  5m;
    client_body_timeout 5m;
    send_timeout     5m;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        auth_basic            "Private Gem Server";
        auth_basic_user_file  .htpasswd;

        if (!-f $request_filename) {
            proxy_pass http://gem_server;

Now you must create your auth basic credentials file on Nginx root path.

$ printf "your_username:$(openssl passwd -crypt your_password)\n" >> /etc/nginx/.htpasswd

Having a private gem server can allow you to manage dependencies through
different gemspecs, which is not possible if you don't have any server with the
gem avaible. Your system need to know about your gem sources.

$ gem sources --add

To use with bundler, add the source at the beginning of your Gemfile's

# Gemfile
source ''
gem 'myprivategem'

That's it, hope you enjoy.

Blog Logo

Endel Dreyer

Full-stack developer. Loves Ruby and JavaScript.



bugfixer / @endel

About programming, tools and solving problems.

Back to Overview