Jason
Jason

Reputation: 2492

Installing pip in /usr/bin instead of /usr/local/bin

So I am trying to upgrade pip. Currently pip is present in /usr/bin but when I upgrade pip using: “pip install --upgrade pip”, it upgrades pip into /usr/local/bin and not /usr/bin. Is there anyway to keep the pip installation in /usr/bin and all the pip libraries in /usr/lib or /usr/lib64, etc ?

Upvotes: 3

Views: 21837

Answers (1)

depau
depau

Reputation: 464

In general, running pip as root is never a good idea. You're installing files to your root that are not tracked by your distribution's package manager.

This may not sound that bad, but in general it is, because you're cluttering your system with files that may clash with others and that you're likely going to have a hard time removing.

Pip is doing the right thing installing itself system-wide into /usr/local. The general convention is that stuff outside of your own directory, of /etc, /var and local system directories is tracked by the package manager.

The package manager will overwrite files outside of these directories without asking. local counterparts of system directories are there to give you the opportunity to install stuff system-wide without it being messed with. However, most of the times, there are better ways of doing it.

For example, the best way with Python is using virtualenvs. They give you an isolated environment that you can activate and install stuff into, including an up-to-date version of pip.

You also can run it as a user (without sudo), but you will have to add its bin directory to your $PATH.

It's best if you leave /usr/bin/pip alone, otherwise bad things may happen.

To answer your question, if you really can't live without having it in /usr/bin or a virtualenv, I'm sad to tell you there is no such documented option for pip. However you have two options:

  1. Remove your distro's pip package, then symlink /usr/bin/pip to /usr/local/bin/pip. That will work but it will still be technically installed in /usr/local. Also, any other program that depends on your distro's pip package will have to be removed.
  2. (very bad) Download pip's sources, then install it with sudo python setup.py install --prefix=/usr. This will place it in /usr/bin, but you should feel really bad for having done it.

I really can't stress enough how bad this practice is, though.

Upvotes: 9

Related Questions