[This is the 3rd part of a series of posts about writing a Ruby gem. The introductory post about this tutorial contains links to each part of the tutorial. Previous post - Adding some code.]
If you’re planning to share your gem with everyone, you have to publish the gem to two places – rubygems.org and github.
Rubygems.org is the place where most Ruby gems are hosted. Whenever you do “gem install some_gem” you’re most likely installing a gem hosted on rubygems.org. Rubygems makes it incredibly easy to make your gem available for anyone to install. Once we have pushed our sudoku gem to rubygems, anyone can install the gem with “gem install sudoku”.
If you don’t already have an account on rubygems.org, create one. Once you have an account, go back to your gem directory and do this:
$ gem push sudoku-0.0.0.gem
Enter your RubyGems.org credentials.
Don't have an account yet? Create one at http://rubygems.org/sign_up
Email: example@gmail.com
Password:
Signed in.
Pushing gem to RubyGems.org...
Successfully registered gem: sudoku (0.0.0)
That’s it! Your gem is now available for anyone to install from rubygems. go on, try installing it:
$ gem install sudoku
Successfully installed sudoku-0.0.0
1 gem installed
Installing ri documentation for sudoku-0.0.0...
Installing RDoc documentation for sudoku-0.0.0...
There… you’ve published your gem to rubygems.org!
Apart from rubygems.org, it’s always a good idea to share your gem’s code on github. Most Ruby programmers are on github and it makes it easy for people to contribute to your gem.
That’s all in this post. In the next part of the tutorial, we’ll add unit tests using Ruby’s built in Test::Unit framework.
[Subscribe to this blog to find out when the next part of this tutorial is published, or keep an eye on the first post in this series where I'll post the links to all published posts.]