Creating Your Own Gem
Build and publish your own Ruby gem for others to use.
Creating Your Own Gem is a free Ruby Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ruby Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Creating Your Own Gem
Ruby allows developers to create their own reusable libraries, called gems.
In this lesson, you will learn how to build and publish a Ruby gem.

2
Starting a New Gem Project
Use Bundler to generate a new gem structure:
bundle gem my_gem3
Understanding Gem File Structure
A generated gem project includes:
lib/: Contains the main gem code.my_gem.gemspec: Defines gem metadata.Rakefile: Used for automation tasks.
4
Writing Gem Code
Edit the lib/my_gem.rb file to define the gem’s functionality.
module MyGem
def self.hello
'Hello from MyGem!'
end
end5
Editing the .gemspec File
The my_gem.gemspec file contains metadata about your gem.
Gem::Specification.new do |spec|
spec.name = 'my_gem'
spec.version = '0.1.0'
spec.summary = 'A simple example gem'
spec.authors = ['Your Name']
spec.files = Dir['lib/**/*.rb']
end6
Building the Gem
Run the following command to create a gem package:
gem build my_gem.gemspec7
Installing and Testing Your Gem Locally
Install your gem locally before publishing:
gem install ./my_gem-0.1.0.gem8
9
Publishing Your Gem to RubyGems.org
To publish your gem, first authenticate and then push the gem:
gem push my_gem-0.1.0.gem10
Congratulations!
You have learned how to create and publish your own Ruby gem.
This concludes the 'Working with Gems and Bundler' section.

Frequently asked questions
Is the “Creating Your Own Gem” lesson free?
Yes — the full text of “Creating Your Own Gem” is free to read here on the web, and the Ruby Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ruby Academy course, upgrade to CoddyKit PRO.
What will I learn in “Creating Your Own Gem”?
Build and publish your own Ruby gem for others to use. You practise Ruby Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ruby Academy?
No prior experience is required. Ruby Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Creating Your Own Gem” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ruby Academy lesson?
Yes. Every Ruby Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- What Are Gems?
- Installing and Using Gems
- Managing Dependencies with Bundler
- Creating Your Own Gem