Build a ruby gem and host it on rubygems.org in 4 easy steps

Build a ruby gem and host it on rubygems.org in 4 easy steps
Photo by Jiawei Zhao / Unsplash

Building a ruby gem these days is really, really easy. Bundler provides a great framework generator to get you started. Bundler also lets you install a gem straight from a github repository, so now is the time to say goodbye to your git submodules and start packaging your code into gems.

  1. Sign up for a rubygems.org account
  2. `bundle gem shiny_new_gem` (This creates the framework for your gem)
  3. Edit `shiny_new_gem.gemspec`, and add your code in your gem's lib folder. (When the gem is required, whatever is in `lib/shiny_new_gem.rb` will be executed.)
  4. # Build the gem
    rake build
    # Push the gem up to rubygems.org
    # (you will be asked for your email and password)
    gem push pkg/shiny_new_gem-0.0.1.gem
    

Done! Now any rails developer can add gem "shiny_new_gem" to their Gemfile, and use your creation. Pretty soon you'll be famous! You'll be hired by important people! You'll buy a boat!

Go build your gems!

Read more