Ruby gems: Using Linux/BSD packages vs. gem install

As a Ruby user and programmer, I thought that Linux distributions and BSD projects offered packaged versions of Ruby gems to add sanity and stability to a computer.

The problem is that every distribution and project packages a different subset of all the Ruby gems available.

I’ve always tried to use as many “packaged” gems as possible in the systems I run — chiefly Debian and Fedora Linux, along with OpenBSD.

If you only need a couple of gems, distribution packages might be the way to go. But once you start to pile up the gems and get one or more with a LOT of dependencies on other gems, the whole thing can get a bit tangled.

The documentation to my blogPoster project has included a lot on how to install gems with package managers like apt. I’m about to pull all of that out in favor of recommending that all Ruby gems be installed with Ruby’s own gem install program.

I asked about it on Twitter, and everybody who responded said DON’T use distro packages and instead use gem install for everything.

I believe them.

The consensus is that the reason Linux distributions and BSD projects package Ruby gems is to satisfy the dependencies for other Ruby software they package. It’s so you can install a .deb or .rpm package of a Ruby program and then get all the dependencies via apt, dnf or yum. It’s not so you can use apt instead of gem install.

Let’s go back: What are Ruby gems? They are little programs/extensions that add functionality to Ruby. You can process files better, do more with networking, and thousands of other things without reinventing any wheels. Somebody else has pre-programmed many of these things and packed them into Ruby gems. Just about any Ruby program can probably be packaged as a gem, though gems are generally Ruby utilities that make it easier to write other programs. Other programming languages like Perl, Python, Node, Golang and Java have similar ways of packaging libraries to help programmers do more with less work.

It gets complicated when I bring in things like the Twitter gem. Very few operating system projects packages it. The Twitter gem has LOTS of dependencies — 10 to be exact . It’s better to use gem install (or sudo gem install in Unix-like systems that use sudo for rootly privileges). Using gem install helps keep the dependencies from getting too thorny.

I just used apt to uninstall all of my Debian-packaged Ruby gems and sudo gem install to bring them all back.

For Ruby developers, there is a utility called bundler that makes sure your application brings in the right gems. I know almost nothing about it. There’s also something called a gemfile. I need to figure these things out and incorporate them into my programs.

Until then, I will be rewriting the blogPoster documentation to remove instructions for installing Ruby gems from distro packages and instead encouraging users to do that with (sudo) gem install.