loading...

What is a Gem? Part 1

clairemuller profile image Claire Muller ・2 min read

Ruby gems, like a lot of things in ruby, can seem pretty magical at times. How is it possible that I can type ‘gem install rails’ into my terminal and be able to create a web application in a matter of minutes? What is this sorcery? I’m on a mission to find out!

Back to the Basics

To really understand a gem, we have to take a few steps back. Basically every aspect of computing involves files; a single file can contain a little or a lot of information. For us to make programs and do cool stuff, files have to be used together. It can quickly get very confusing to keep track of what every file is doing. Enter: packages. A package is simply a collection of files and metadata (data that describes other data).

Gems

In Ruby, these packages are called gems. Gems contain code, documentation, and a gemspec. One of the most widely used gems is bundler, which is able to look in your Gemfile and download the correct version you need for your program. Another popular gem, rails, is an entire web application framework that makes building web apps quick and easy.

Package Management

Just like files, packages can get messy to deal with. A package manager, as the name implies, is software that manages these packages for you. A great example of a package manager that we’ve all used is an app store. A user can easily search for, install, or delete an app without having to do the dirty work of checking dependencies or manually installing each file within the package. Everything is handled for you, so you can get to the good stuff! With the release of Ruby 1.9 in late 2007, the package manager RubyGems became Ruby’s default package manager.

Conclusion

There is a lot more to be said about gems! For my next post, I’ll dive deeper into what makes up a gem, including the structure and gemspec file. But to summarize for now: gems are packages used in ruby to make programming easier for us. Catch you next time!

Discussion

pic
Editor guide