Last Updated: February 25, 2016
·
1.545K
· mxcl

Getting gem and pip to install to ~ by default

I hate to sudo, so I spent some time figuring out how to make it so I can gem and pip on Mavericks without sudo.

With gem:

echo 'gem: --user-install' >> ~/.gemrc

Now gems will install to ~/.gem. Which means you also will need to edit your .bash_profile and append:

if which ruby >/dev/null && which gem >/dev/null; then
    PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi

For Python, you firstly must install pip (sadly, via sudo):

sudo easy_install pip

Very annoyingly, this installs to /usr/local/bin, so now brew doctor will complain about it (also this will also prevent you installing brew’s Python 100% effectively).

Then you need to create a bash function in your .bash_profile that will invoke pip with --user as appropriate:

function pip {
    if [ "$1" == "install" ] || [ "$1" == "bundle" ]; then
        /usr/local/bin/pip $1 --user ${@:2}
    else
        /usr/local/bin/pip $@
    fi
}

test -d ~/Library/Python/2.7/bin && PATH=~/Library/Python/2.7/bin:$PATH

I'm not especially happy with the pip solution.

2 Responses
Add your response

Don't RVM and VirtualEnv solve that problem, for Ruby and Python respectively?

over 1 year ago ·

Homebrew's Python comes with pip, so I just use that. Then, it just installs to Homebrew's Python's site-packages folder.

over 1 year ago ·