It’s easy to make your own Ruby gem. Even without a library to help you. If you have RubyGems installed you’re already good to go.
First, make a directory for your project. In that directory make gemspec file named after the gem. For example, my_awesome_gem.gemspec
. The gemspec file is just Ruby. Here’s a basic example:
Now just put your code in lib/my_awesome_gem.rb
. RubyGems will automatically put your lib
directory into the load path when the gem is installed. To test your gem before it’s installed just run your test script using ruby -Ilib my_test_file.rb
.
Now build your gem with gem build my_awesome_gem.gemspec
and push it to RubyGems.org by running gem push my_awesome_gem-0.0.1.gem
. You’ll need to make a RubyGems.org account if you don’t have one. The gem push command will ask you for your account info the first time you push a gem.
As a bonus, if you want to use rake to build and push your gem, just make a Rakefile
like this (run rake -T
to see what this gives you):
And if you want to manage your development gems with bundler, just put this in your Gemfile
: