How can I upgrade pip to the latest version?

I usually just run the following commands to upgrade both pip2 (=pip by default) and pip3:

sudo -H pip3 install --upgrade pip
sudo -H pip2 install --upgrade pip

You must make sure that you upgrade the version (for Python 2 or 3), which you want to react on the command pip without number, last.

Also please note that this keeps the old packaged versions installed through apt-get or any other package manager, but adds new versions which have nothing to do with the system packages. The pip-installed packages will be preferred, but you should not remove the apt-get-installed ones either, because the package manager can't know that any pip version is installed otherwise.


I think the

pip install --upgrade pip

command does not work properly anymore. The correct command should be:

  • for Python 3:

    python3 -m pip install --upgrade pip
    
  • for Python 2:

    python2 -m pip install --upgrade pip
    

P.S. If you want to make sure your other Python packages are also up to date, follow the instructions here.


Go to the website https://pypi.python.org/pypi/pip.

Copy (or download) the source link (ends in .tar.gz).

For 9.0.1, the link is https://pypi.python.org/pypi?:action=show_md5&digest=35f01da33009719497f01a4ba69d63c9.

Installation procedure:

wget Link goes here
tar -xzvf pip-9.0.1.tar.gz
cd pip-9.0.1
sudo python3 setup.py install

The version should be changed to the latest version and the link can be updated with the latest version's link.

This should work.


I think it's worth mentioning that what I'm explaining below is if you expect pip to point to Python 2 and pip3 to point to Python 3. The reason I mention this is because when you upgrade pip3, it also takes over the pip command as well. This is a somewhat strange convention because by default python points to 2.x and python3 points to 3.x. That being said...

If you want to have the latest versions of python 2.x pip and python 3.x pip3 coexist on the same machine (using pip for 2.x and pip3 for 3.x), you need to do the following:

sudo apt-get install python-pip python3-pip --yes
sudo python3 -m pip install pip --upgrade --force
sudo python -m pip install pip --upgrade --force # this line associates pip with Python 2

The other answers provided by others fail to mention that after running sudo pip3 install pip --upgrade you'll end up with the pip command installing packages in the python 3.x directories instead of the python 2.x directories.

Part of me thinks that we should just leave pip be after upgrading pip3 (even if it pip -> pip3), but there's a danger there that people already have an expectation that pip functions like python - both pointing to python 2.x. In other words, people are probably trained to use pip/python for python 2.x just like they are trained to use pip3/python3 for python 3.x.


pip install -U pip

The shortest I know.