How to Install Python Package Manager pip on UNIX/Linux/macOS
Determine If pip is Installed on UNIX/Linux/macOS
On some UNIX/Linux/macOS systems, Python and pip are pre-installed. If you are unsure whether your system has pip available, you can determine this by entering the following command, which will display information about pip when it is available.
python3 -m pip --version
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)
pip3 -V
pip 23.2.1 from /usr/lib/python3.12/site-packages/pip (python 3.12)
Python Installation
To learn how to install Python on UNIX/Linux/macOS, you can check out the article How to Install Python on UNIX/Linux/Windows/macOS.
Install pip on UNIX/Linux
Since most UNIX/Linux systems provide their own source for installing pip packages, you can install pip with a simple command.
In FreeBSD, you can use the command pkg install py<XY>-pip
, where X
denotes the major version number of Python and Y
denotes the minor version number of Python, to download the pip for the corresponding version of Python, e.g., pkg install py39-pip
. In OpenBSD, you can use the command pkg_add py3-pip
.
pkg install py<XY>-pip
pkg_add py3-pip
In Debian, you can install pip with the command sudo apt install python3-pip
. In Fedora, you can install pip with the command sudo dnf install python3-pip
. In openSUSE, you can install pip with the command sudo zypper install python3-pip
.
sudo apt install python3-pip
sudo dnf install python3-pip
sudo zypper install python3-pip
Use the sudo command to elevate privileges
The sudo
command used above will temporarily elevate the privileges to ensure that the pip installation will work.
Install pip on macOS Using the Package ensurepip or the Script File get-pip.py
After determining that pip is not installed in macOS, you can search for and open a Terminal in Launchpad and install pip via the Python package ensurepip
with the following command.
python3 -m ensurepip
The prerequisite for using ensurepip
is that the package ensurepip
must exist and be found by Python, so if you can’t install pip via ensurepip
, then try get-pip.py
. This involves downloading the script file get-pip.py
, then switching Terminal to the download directory, and finally executing get-pip.py
with Python.
python3 get-pip.py
Run Python Script Files, Modules, Packages
To learn more about executing Python scripts from the command line, you can check out the article How to Run Python Scripts Files, Modules, Packages from the Command Line.
The Installation Location of pip on UNIX/Linux/macOS
For UNIX/Linux, pip is generally located in the directory /usr/bin
. However, pip may also appear in the directory /bin
, and some systems link /usr/bin
and /bin
, and the two directories may display the same content.
For macOS, if pip is installed using ensurepip
or get-pip.py
, pip will be located in the directory of the Python that performed the installation task, which may be in the current directory of the Terminal or determined by the environment variable PATH
.