a-akng
Last Updated: February 25, 2016
·
1.022K
· mxcl
Img 0719

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.

Say Thanks
Respond

2 Responses
Add your response

11909
Avatar ika

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

over 1 year ago ·
13257
40e15162d5f9bd4f753257400c843f57

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 ·