TL;DR
To install Ruby Gems without sudo, access your terminal profile dot file of choice and add the lines:
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
I have shamelessly stolen this explanation from the Cocoapods installation guide.

A Tale of Splat

My career path has been a touch unguided. I’ve enjoyed it immensely; the individual voyage of discovery allowing me to hop from thought to thought. Nary a care in the world about where the next spark of inspiration would take me. An intellectual nomad wandering this big world of ours. Like Caine in Kung Fu.

Or Frogger.

And like Frogger occasionally (or often) you go splat.

My history with gem install is a tale of splat.

Sudon’t

Years ago, working in the DC start up scene was my first big opportunity with a large, polyglot team. Ruby developers; Javascript developers; Objective-C developers. Devs fresh out of school. Devs with 20 years experience. Designers and product managers and QA. Oh my!

I did, and do, have an interest in backend development. At this particular organization that meant Ruby development. One of the contractor managers there turned me onto a little piece of technology for blogging that you may have noticed: Jekyll.

It was still pretty new at the time. Github Pages had just begun service. All in all, it was the new hottness. And so I decided to give it a try.

This is where things started going south. There was a bit of a learning curve, not the least of which was: how do you get the thing installed. If you check out Jekyll’s home page they say simply enough gem install jekyll. And that should be it, right.

Right?

No. Not so much. I began getting error messages long since lost to time, that I don’t even care to look up or try reproducing. After not too long I eventually reached out to a collegue about how to get it installed.

Oh, just use “sudo”.

It would be years before I repaired the damage that advice wrought.

RVMind Your Own Damn Business

Several years and at least one job change later my builds have gotten more complex. It’s not enough to just hit “Archive” under Xcode anymore. Now the build needs specific gems in order to function.

I had finally adopted Cocoapods, but I did so using Stackoverflow instead of reading the instructions. I should have.

Instead I started using RVM. RVM has a lot of advantages. For legacy reasons I still use RVM, but I’m trying to dig myself out of that. There’s nothing wrong with it, but I’m an iOS developer who occasionally needs Ruby tools. RVM is too much car for me.

A piece of that is gemsets. At this point, today, I have no idea what gemsets are for. What I was using gemsets for was to install specific gems for use in a given project. Then I could use RVM to switch to a different gemsets manually.

If you know things about Ruby you’re probably a little angry right now and about to get angrier.

Gemfile This Under “Too Much”

Manually switching between gemsets quickly got to be fantastically frustrating. I need to remember which one to use. I need to remember to do it! I found myself asking if there is a way to automate it?

Spoilers: There is!

RVM allows you to setup a Project Gemfile. The idea is that you can specify the ruby you want and what to name the gemset in your gemfile. So if you want a specific gemset for your app you would add this to the Gemfile:

#ruby=ruby-2.2.2
#ruby-gemset=my_appv2.3.4

Now whenever you enter that directory, RVM will check for a gemset my_appv2.3.4 on the installed ruby ruby-2.2.2. If it doesn’t exist, you cn set RVM to install it automatically. Now whenever I need to setup an iOS project the first thing I do is setup my Gemfile with the version of Cocoapods I want to use. Similarly, whenever I want to start a new Jekyll project the first thing I do is setup my Gemfile.

No fuss, no muss.

Right.

Right?

PATH Found

After a lot of mistakes and bad advice. And personal apathy, I think I finally figured out how to use ruby on my system.

First, use your system Ruby. There’s no need to install anything if you have a Unix like system. If you do have to install a custom Ruby, install exactly one. If you’ve gotten to the point where you need a Ruby Version Managment system, you’ve grown beyond this blog post. But, remember, when I say “need” I mean “I need oxygen in the next three minutes”.

Second, setup your GEM_PATH so that you can install gems without using sudo. It turns out it’s pretty simple. Just open your dot profile of choice and add the following lines

GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH

Third, install your tools. And only your tools. Cocoapods and Jekyll are installed on my system so that they’re functional tools from my command line that can be used to Do Things.

Finally, use Gemfiles. But without those pesky RVM annotations. Once that’s done, by using bundle exec in your scripts, bundler will find the version of the gem defined in the Gemfile. Multiple versions of gems can and do coexist without conflict. It’s fantastic and simple.

For the longest time I really resisted doing this because I don’t like letting magic happen. I got over it.