Starting a gem file from scratch

If you are creating a new repository that is a future gem, here is the best way to do it:

bundle gem <gem_name>   #! Make sure gem_name is with “_” and not “-” because otherwise it will create each word between the “-” as a subfolder of lib, which can get pretty deep and unnecessary.

Now you can cd gem_name

Make sure to update you gem_name.gemspec and don’t forget to work on your gem and make it great!

Now you are ready to build your gem — update the lib/gem_name/version if this is not your first publish. Run gem build gem_name.gemspec 

Please note the gem file name has probably been changed from gem_name to gem-name-<version>.gem. You should see it as output after you have built your gem and in your directory as well.

Our gem has been created! If you want to publish to rubygems.org, make sure you have created your account. If this is your first time publishing a gem to rubygems.org you will be prompted for your credentials. If it’s not your first, your credentials are saved to your system.

Run gem push gem-name-<version>.gem and your gem should successfully register to rubygems.org

 

Sources:

http://bundler.io/rubygems.html

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

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner