Installing pip on an Ubuntu Linux Machine

If you have just installed a new Ubuntu 20.04 Operating System on your machine, you should find it having Python3 pre-installed. Now, to start installing and using external packages in your Python projects, you would need pip installed on your machine as well.

One of the easiest ways to install pip is to install the package python3-pip via the apt repositories with the command:

sudo apt install python3-pip

or using apt-get with the command:

sudo apt-get python3-pip

This will install pip for all users in the /usr/bin/ path.

However, sometimes users may not have root (or sudo) privileges and can not simply run:

sudo apt-get install python-pip

In such a situation, users can still install and use pip without root (or sudo) access in a local directory by following the below steps:

  • First, download pip from an online repository using wget:
    wget https://bootstrap.pypa.io/get-pip.py
    
  • Install the downloaded package into a local directory: bash python3 get-pip.py --userbash This will install pip on your local directory in your home (~/.local/bin).
  • Now you may navigate to this directory:
    cd ~/.local/bin
    
  • You can start using the command pip now to start downloading Python packages. But the ideal thing is to add this path of pip to your $PATH variable to run pip from anywhere by running:
    PATH=$PATH:~/.local/bin
    
  • Finally, apply the changes and relaunch .bashrc:
    source ~/.bashrc
    

Now, you can install Python packages using pip using pip install <package_name> and they will be installed in the ~/.local/ directory and will only be available to the current user.