How to install PIP in Linux without sudo?

Whether you are using Ubuntu, Linux Mint, Debian, Redhat, or any other Linux, if you don’t have sudo rights or just for security reasons want to install PIP python package manager but without sudo rights then here is the solution for that. 

Just like every Linux system has its own package manager to manage all system packages, similarly Python also has a package manager to install and manage its various library and modules without using sudo.

Let’s take an example of Ubuntu Linux where the default package manager is APT but needs sudo access or rights to install any package. But what, if we don’t want or have rights to use sudo to install PIP, if not installed already on your system? In that, case we can go for a script to set up PIP for us in our local directory.

Now let’s discuss the steps for installing PIP without sudo on Linux.

1. Download the get-pip.py script

There is a script offered by the Python Packaging Authority (PyPA) to install the PIP on a system that already has Python to manage its libraries. The key benefit of using this script is it allows users to install PIP without the need for administrator privileges or relying on the system package manager.

Your system would already have the curl or wget tool to download things from the internet but directly in the command terminal. So, use whatever of the two is available:

For CURL users:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

or

For Wget users:

wget https://bootstrap.pypa.io/get-pip.py

The source of the script is available on its GitHub page.

2. Install PIP without SUDO in Linux

Now, using the download get-pip.py script we can install the PIP package manager in our local directory but without using any sudo rights. However, make sure your system already has Python installed otherwise you won’t be able to run the script that is written in Python.

Here is the command to execute the downloaded script for the current user:

python get-pip.py --user
Install PIP without SUDO

3. Add the PIP directory to your system path

As we have not used sudo to install PIP, we can’t use it without switching to its directory where its binary is present that is ~/.local/bin. So to make things easy and execute the PIP globally for your current user add its folder by configuring your system $PATH variable.

Edit the Bashrc file and at the end of it, add the following line:

nano ~/.bashrc

Add the following line at the end.

PATH=$PATH:~/.local/bin

Save the file by pressing Ctrl+X, after that Y, and then hit the Enter key.

Now source your current session to apply the changes:

source ~/.bashrc

4. Check the PIP version

Well, now we can confirm whether PIP is actually available on our Linux system or not. For that check its version by using the given command:

pip -V
Check the PIP version

5. How to downgrade or upgrade PIP

In the future, if some update is available for your currently installed PIP version then upgrade it using the given command:

pip install --upgrade pip --user

Whereas, those who want to downgrade the current PIP for some reason, can use the given command syntax:

pip install pip==version--user

Replace the version with the exact version to which want to downgrade the PIP, for example, if you want to use 20.2.1 instead the current one then the command will be like this:

pip install pip==20.2.1 --user

6. Uninstallation (optional)

In the future, if you don’t require PIP anymore on your system installed using get-pip script then to remove it from your Linux, simply delete the PIP binaries where it has been installed (~/.local/bin) and after that also remove it from the PATH we have added in BASHRC file.

rm ~/.local/bin/pip*

Also, delete the line added in Bashrc by editing it- nano ~/.bashrc

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.