Last Updated: February 25, 2016
·
623
· mose

Make a gem

Making and publishing your own gems is so incredibly simple. Here is my setp by step process when I want to publish one:

Make a Rubygems account

curl -u username https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
Enter host password for user 'username':

chmod 0600 ~/.gem/credentials

Prepare the code

These steps are my typical path, nothing is really mandatory there.

  • create a repo at github (or wherever you want)
  • create a base gem skeleton bundle gem mycoolgem
  • update the README.md, add some minimal information. The clearest you explain what it does the best chances people will adopt it. Add cypirght information
  • create a CHANGELOG.md because when you publish something you need a clear log of your version changes
  • enable the tracking on [codeclimate][1], [travis][2], [coveralls][3], [gemnasium][4]
  • add badges from http://shields.io in the README.md because it helps to qualify the state of the code quickly
  • when the gem code don't need to have access to the version number, I found convenient to just remove the version file and add version in the .gemspec from the changelog file with spec.version = File.read(File.expand_path('../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/] (so then when I version bump there is only one file to edit)
  • write the code (or copy it from the private app you extract it from)
  • add a spec/ or test/ dir and write some tests and try to reach a decent coverage

Release it

  • add the date in the changelog for the current version
  • rake release
  • bump the version to the next increment in the changelog (and version file if any)

Overall with the initial bundle command and the final rake task for release, it's pretty straightforward.

Also check http://guides.rubygems.org/make-your-own-gem/

[1]: https://codeclimate.com/
[2]: https://travis-ci.org/
[3]: https://coveralls.io/
[4]: https://gemnasium.com