Python is one of the most versatile and widely-used programming languages in the world. Whether you’re interested in data analysis, web development, automation, or scientific computing, Python can be your go-to tool for almost any project. If you’re using Ubuntu, you’re in luck — Python is available and easy to install.
In this guide, we’ll walk you through the process of install Python on Ubuntu. Whether you’re a complete beginner or a more experienced developer, this tutorial will provide the latest, step-by-step instructions for installing Python on your system. We’ll cover how to install Python 3, how to install a specific version such as Python 3.9, and how to set Python 3 as the default Python version on your Ubuntu machine.
By the end of this article, you’ll have Python up and running smoothly on your Ubuntu system and will be ready to start coding.
Why Install Python on Ubuntu?
Ubuntu is one of the most popular Linux distributions for developers, and it comes with a lot of built-in tools. Python is often pre-installed, but you may need to install a newer version or configure it for specific use cases, such as development, automation, or data science.
Here are a few reasons why you might want to install Python on your Ubuntu system:
- Python is widely used in data science, web development, and automation: Many tools and frameworks, like Flask, Django, Pandas, and TensorFlow, are built using Python.
- Python’s ease of use: Python is a beginner-friendly programming language with a simple syntax.
- Customization: You can install specific Python versions for your needs, such as Python 3.9 for compatibility with certain packages or projects.
- Virtual environments: You may want to install Python to create isolated environments for different projects.
Installing Python on Ubuntu gives you flexibility and control over your development environment.
Prerequisites: What You Need Before Installing Python
Before we get started with the installation, ensure that your system is up to date and has the necessary tools installed. You will need:
- Ubuntu: This guide assumes you’re using an Ubuntu-based system.
- Internet Connection: You’ll be downloading packages and updates from the Ubuntu repositories.
- Access to Terminal: Ubuntu’s terminal is the primary tool for installation. You can open it by pressing
Ctrl + Alt + T
or searching for “Terminal” in the application menu.

How to Install Python on Ubuntu Using the Terminal?
The easiest way to install Python on Ubuntu is through the terminal using the built-in package manager, apt
. Here’s how to do it:
Installing Python 3.x
- Update the package list
First, update the list of available packages to make sure you’re getting the latest version. Open the terminal and type:sudo apt update
- Install Python 3
Python 3 is the latest and recommended version for most projects. To install Python 3, run the following command:sudo apt install python3
This command will download and install Python 3 along with any necessary dependencies. - Verify Python Installation
Once the installation is complete, verify that Python has been installed correctly by checking the version:python3 --version
You should see something like this:Python 3.x.x
This confirms that Python 3 is successfully installed on your Ubuntu machine.
How to Install Python 3.9 on Ubuntu
If you specifically want Python 3.9, or if you need this version for compatibility with certain libraries or projects, here’s how to install it:
Step 1: Add the Python 3.9 PPA (Personal Package Archive)
By default, Ubuntu may not have the latest versions of Python available through the standard repositories, especially for older versions like 3.9. To install Python 3.9, you need to add the PPA repository:
sudo add-apt-repository ppa:deadsnakes/ppa
This command adds the PPA repository containing newer Python versions, including Python 3.9.
Step 2: Update the Package List
Next, update your package list again to include the newly added PPA:
sudo apt update
Step 3: Install Python 3.9
Now, you can install Python 3.9 by running the following command:
sudo apt install python3.9
Step 4: Verify the Installation
Finally, verify that Python 3.9 has been installed successfully:
python3.9 --version
You should see:
Python 3.9.x
Now you have Python 3.9 installed on your Ubuntu system.
How to Set Python3 as Default Python on Ubuntu
By default, Ubuntu might use Python 2.x when you type python
in the terminal. To make Python 3 the default version of Python on your system, you can update the symbolic links.
Step 1: Check for Existing python
Symlink
First, check if python
is pointing to the right version:
python --version
If it returns a Python 2.x version, you’ll need to set Python 3 as the default.
Step 2: Update the python
Symlink
To change the default Python version, use the update-alternatives
command. First, add Python 3 as an alternative:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
Then, set the default Python version:
sudo update-alternatives --config python
This will display a list of available Python versions. Enter the number corresponding to Python 3.x (e.g., Python 3.8 or Python 3.9), and press Enter.
Step 3: Verify the Change
Now, check that the python
command points to Python 3:
python --version
It should return the version of Python 3 that you installed.
Managing Python Versions on Ubuntu
Sometimes, you might want to manage multiple versions of Python on your system. For example, you might need Python 2 for legacy projects and Python 3 for newer projects.
Using update-alternatives
to Manage Multiple Versions
You can use the update-alternatives
system to manage multiple versions of Python. Here’s how:
- Add both Python 2.x and Python 3.x as alternatives:
sudo update-alternatives --install /usr/bin/python2 python2 /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
- Select the default Python version using
sudo update-alternatives --config python
, and then select the version you prefer.
Installing Python Packages Using pip on Ubuntu
After installing Python, you’ll probably want to install Python packages using pip
, which is Python’s package manager.
Installing pip for Python 3
If pip isn’t already installed, you can install it with the following command:
sudo apt install python3-pip
Installing Packages with pip
To install a Python package using pip, simply use the following command:
pip3 install package-name
For example, to install the requests
library:
pip3 install requests
You can verify that the package was installed by importing it in Python:
import requests
Troubleshooting Common Issues When Installing Python on Ubuntu
While installing Python on Ubuntu is straightforward, you may run into some issues. Here are a few common problems and solutions:
- Issue:
command not found: python3
This error means Python 3 is not installed. Try reinstalling Python using the instructions above. - Issue: Old Python Version
If you have an outdated version of Python, make sure you have added the correct PPA or updated your package list before installing the desired version. - Issue: Permission Denied Errors
If you receive permission errors when installing Python or pip packages, try addingsudo
before the command to gain administrative privileges.
Conclusion
Install Python on Ubuntu is a relatively easy process, whether you’re setting up Python 3 for the first time, installing a specific version like Python 3.9, or setting Python 3 as the default version. By following the steps in this guide, you’ll have Python up and running in no time.
Now that you have Python installed, you can start developing your own Python applications, working with data, or automating tasks. If you run into any issues, refer back to the troubleshooting section, and you’ll be back on track quickly.
Did this guide help you? Share your thoughts in the comments, or explore related content to learn more about Python development on Ubuntu! Happy coding!