Without sudo, how do I install PIP in Linux?
If you don't have sudo permissions or just wish to install PIP Python Package Manager without sudo rights for security concerns, regardless of whether you use Ubuntu, Linux Mint, Debian, Redhat, or any other Linux distribution, here is the solution.
Python has a package manager to install and manage its different libraries and modules without the need for sudo, much like every Linux system has one to manage all system packages.
Let's use Ubuntu Linux as an example, where the default package manager is APT, but installing any package requires sudo access or certain rights. But what if we don't want to or don't have the authority to install PIP using sudo if it isn't already on your system? In that situation, we can use a script to install PIP in our local directory.
How to install PIP on Linux without using sudo.
1. Download the get-pip.py script
The Python Packaging Authority (PyPA) has a script available to install the PIP on a system that already uses Python to manage its libraries. The main advantage of using this script is that it enables users to install PIP without requiring administrator rights or via the system package manager.
The curl or wget tools are already installed on your computer and may be used in the command line to download files from the internet. Use one of the two options that are available.
CURL users should:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Wget users should:
wget get-pip.py bootstrap.pypa.io
On its GitHub page, the script's source code is accessible.
2. Install PIP in Linux without SUDO
Using the get-pip.py script that we downloaded before, we can now install the PIP package management in our local directory without the need for sudo privileges. However, to run the Python script, make sure Python is already installed on your machine. Otherwise, you won't be able to.
The command to run the downloaded script for the current user is as follows:
python get-pip.py --user
3. Add the PIP directory to your system path
PIP cannot be used without being switched to its directory, which is /.local/bin, because sudo was not used to install it. Thus, by specifying your system's $PATH variable, you can add its folder and execute the PIP globally for the current user to make things easier.
Edit the bashrc file and add the next line at the end:
The last line should be included.
By hitting Ctrl+X, Y, and the Enter key, you can save a file.
To apply the modifications, source your current session right away:
4. Verify PIP version.
We can now determine whether PIP is genuinely present on our Linux system. For that, use the following command to check its version:
Verify PIP version
5. How to change the PIP's level
If a future update for the PIP version you currently have installed becomes available, upgrade it with the following command:
pip install --user pip upgrade
In contrast, the following command syntax can be used to downgrade the current PIP:
installation of pip==version--user
To downgrade the PIP, replace the version with the actual version; for instance, if you want to use version 20.2.1 in place of the current one, the command would be as follows:
Installing pip==20.2.1 with --user
6. Uninstall (Optional)
In the future, if you no longer need PIP on your system installed using the get-pip script, you can remove it from Linux by first deleting the PIP binaries in the /.local/bin directory where it was installed, and then by removing it from the PATH we added in the BASHRC file.
Delete the line that was added to Bashrc by using the nano command in /.bashrc.
Join the conversation