Python is one of the most versatile and widely used programming languages in the world, essential for everything from simple web scraping scripts to advanced machine learning models. If you are setting up a new Ubuntu server for development, getting Python up and running is likely your very first priority.
Fortunately, Canonical (the company behind Ubuntu) embraces Python so deeply that they usually include it as a core system component. However, you often need to manually install the specific version you want, along with the crucial pip package manager. Here is how to install Python on Ubuntu.
Step 1: Check if Python is Already Installed
Before you start downloading anything, check what is already on your system. Modern versions of Ubuntu (20.04 LTS and newer) come with Python 3 pre-installed by default.
- Open your terminal or connect to your server via SSH.
- Type the following command:
python3 --version - Press Enter.
If the terminal returns a version number (like Python 3.10.12), you are already good to go! If it returns an error saying “command not found,” proceed to the next step.
Step 2: Update the Package Repository
Before installing any new software on Linux, you must always update the apt package manager’s internal index. This ensures you download the latest security patches and the most recent version of Python.
- In the terminal, type:
sudo apt update - Press Enter, type your administrator password if prompted, and wait for the list to refresh.
Step 3: Install Python 3
Now you can download the actual Python binaries directly from the official Ubuntu repositories.
- Type the installation command:
sudo apt install python3 - Press Enter.
- The terminal will calculate the file size and ask, “Do you want to continue? [Y/n]”. Type Y and press Enter.
The system will automatically download, unpack, and configure Python. Once the command prompt returns, verify the installation by typing python3 --version again.
Step 4: Install PIP (Crucial for Developers)
Python by itself is powerful, but its true strength lies in its massive ecosystem of third-party libraries (like NumPy, Requests, or Django). To download these libraries, you absolutely need pip (the Python Package Installer).
Surprisingly, Ubuntu does not install pip by default alongside Python.
- To install pip, type the following command:
sudo apt install python3-pip - Press Enter and confirm the installation by typing Y.
Once finished, you can verify it is working by typing pip3 --version. You are now fully equipped to start writing code and installing external packages on your Ubuntu machine.