The problem: I need to install CocoaPods, but I don't want to litter my system with the various gems it requires.
I tried to use Homebrew Cask, but it broke with my setup where I have Homebrew installed
in /opt/brew and no write access to /usr/local.
There's probably a solution that involves RVM or rbenv, but I couldn't don't know those tools and I couldn't find one that was neatly packaged and simply explained.
Solution:
- Start with a system with no gems installed in the user's home directory
- Install cocoapods with
gem install --user-install cocoapods - Create
.localgemsin your home directory:mkdir ~/.localgems - Rename
.gem:mv ~/.gem ~/.localgems/cocoapods - Ensure
~/binis in your$PATH - For each executable in cocoapods (
~/.localgems/cocoapods/ruby/2.0.0/bin/on my system), add a shell script with the same name to~/bin, with the following contents:
#!/bin/sh
# Runs executable with the same name from a locally installed gem copied to a new directory
INSTALL_DIR=$HOME/.localgems/cocoapods/ruby/2.0.0
export GEM_PATH=$GEM_PATH:$INSTALL_DIR
EXECUTABLE=$(basename $0)
$INSTALL_DIR/bin/$EXECUTABLE "$@"