Fork me on GitHub

Publishing a gem with Bundler fails silently the first time

by Nick on March 30, 2011

If you’re writing your first gem and publishing it with Bundler, you may run into the same problem as myself.  The issue is that when pushing to http://rubygems.org, Bundler will report a success when it has actually failed.  To start the process of deploying a gem for the first time, Bundler offers several rake tasks:

nick@nick-laptop:~/Coding/rottentomatoes$ rake -T
(in /home/nick/Coding/rottentomatoes)
rake build # Build rottentomatoes-1.0.1.gem into the pkg directory
rake install # Build and install rottentomatoes-1.0.1.gem into system gems
rake release # Create tag v1.0.1 and build and push rottentomatoes-1.0.1.g...

Deploying the gem is easy.  The only command you need to run is rake release.  This will automatically handle tagging based on the version file, building the gem into the pkg folder, and then pushing to rubygems.  When you first run the command, the output looks like:

nick@nick-laptop:~/Coding/rottentomatoes$ rake release
(in /home/nick/Coding/rottentomatoes)
rottentomatoes 1.0.1 built to pkg/rottentomatoes-1.0.1.gem
Tagged e67663fc with v1.0.1
Pushed git commits and tags
Pushed rottentomatoes 1.0.1 to rubygems.org

Great.  We’re done, right?  Unfortunately, trying to install the gem afterwards fails with an error saying the gem could not be found.  The issue is that there is no configuration setup for rubygems.  To fix this, create an account at http://rubygems.org and get your API key from the settings page.  Then create the file ~/.gem/credentials with the following content:

---
:rubygems_api_key: my_provided_api_key

You can then rerun the push command with gem push:

nick@nick-laptop:~/Coding/rottentomatoes$ gem push pkg/rottentomatoes-1.0.1.gem Pushing gem to RubyGems.org...
Successfully registered gem: rottentomatoes (1.0.1)

That’s it!  Ideally Bundler would let the user know that their credentials need to be setup first but it’s an easy fix.

Leave your comment

Required.

Required. Not published.

If you have one.