Can't install gems on OS X "El Capitan"
Disclaimer: @theTinMan and other Ruby developers often point out not to use sudo
when installing gems and point to things like RVM. That's absolutely true when doing Ruby development. Go ahead and use that.
However, many of us just want some binary that happens to be distributed as a gem (e.g. fakes3
, cocoapods
, xcpretty
…). I definitely don't want to bother with managing a separate ruby. Here are your quicker options:
Option 1: Keep using sudo
Using sudo
is probably fine if you want these tools to be installed globally.
The problem is that these binaries are installed into /usr/bin
, which is off-limits since El Capitan. However, you can install them into /usr/local/bin
instead. That's where Homebrew install its stuff, so it probably exists already.
sudo gem install fakes3 -n/usr/local/bin
Gems will be installed into /usr/local/bin
and every user on your system can use them if it's in their PATH.
Option 2: Install in your home directory (without sudo)
The following will install gems in ~/.gem
and put binaries in ~/bin
(which you should then add to your PATH
).
gem install fakes3 --user-install -n~/bin
Make it the default
Either way, you can add these parameters to your ~/.gemrc
so you don't have to remember them:
gem: -n/usr/local/bin
i.e. echo "gem: -n/usr/local/bin" >> ~/.gemrc
or
gem: --user-install -n~/bin
i.e. echo "gem: --user-install -n~/bin" >> ~/.gemrc
(Tip: You can also throw in --no-document
to skip generating Ruby developer documentation.)
In my case, I had to re-install Ruby using Brew. That seems to have solved the problem as I can install gems again.
brew install ruby
After this, you need to log out and log back in, either graphically or just restarting your terminal.
That is because of the new security function of OS X "El Capitan".
Try adding --user-install
instead of using sudo:
$ gem install *** --user-install
For example, if you want to install fake3 just use:
$ gem install fake3 --user-install