Install Gems Without sudo in macOS
I came across a neat little command line tool via Rob Griffiths’ Robservatory this morning, a Ruby gem named iStats1. Install is easy enough in Rob’s example, sudo gem install iStats
, except that when you use sudo
to install gems you are using the default macOS Ruby, and installing to system paths.
While that might be fine, my personal preference is to keep the core system as close to default as possible. I once ran into an issue keeping Jekyll up to date, so now I use the excellent Homebrew to install an updated version of Ruby and keep the gems in /usr/local
, which is entirely mine and safe to write to.
brew install ruby
Also, I make sure that /usr/local/bin
is called before /usr/bin
in my shells PATH variable.
export PATH=/usr/local/bin:~/Unix/bin/:$PATH
Now I can call gem install iStats
and the gems will be installed safely, keeping my core system clean and my gems easily updatable.
-
As Rob points out, this is apparently not associated with iStat Menus. ↩