Easily publish your ruby gems

In my earlier post, I covered the basics of creating a ruby gem. At the end, show the release rake task to tag, build and release your gem. But you might get an error when doing this:

$ rake release
my_gem 0.0.1 built to pkg/my_gem-0.0.1.gem.
Tag v0.0.1 has been created.
rake aborted!
Your rubygems.org credentials aren't set. Run `gem push` to set them.

Tasks: TOP => release
(See full trace by running task with --trace)

In contrast of using the gem push command, you won’t be asked to fill in your rubygems.org credentials. Instead, the release rake task is depending on your rubygems.org API key that is by default stored in ~/.gem/credentials .

$ curl -u your-rubygems-username https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials

Replace your-rubygems-username with your proper rubygems.org username. You will get prompted with a request to enter your password. When you enter the correct password, your API key will get stored in the credentials file under the ~/.gem directory.

Once your API key is set, you’ll be able to publish your gems using the provided rake task.