Python is a popular programming language mostly used for web development, data analysis, artificial intelligence, and more. In this guide, you will learn how to install Python 3 on your Ubuntu 20.04 or 22.04 system quickly and easily.
- Start with the Ubuntu Update:
First, ensure you have the latest package updated in your system:
sudo apt update - Check your current Python version:
It is important to check the latest version that you have installed on your system. Check it using:
python –V - Install the supporting software:
If you install supporting software, you can manage packages and add a PPA repository too.
sudo apt install software-properties-common - Add Deadsnake PPA:
Sometimes we might not get the latest Python version, so we need to add Deadsnake PPA to get the newer version.
sudo add-apt-repository ppa:deadsnakes/ppa Press Enter to continue and update the package list once again:
sudo apt update - Installing Python on Ubuntu:
After adding the PPA repository, you can install all the latest versions of Python on Ubuntu. To check if the version is available, use:
sudo apt-cache policy python3. X
(Note: Replace the X with the version you want to install—.11,.12,.13.) - Set the default Python version:
List out all the Python versions available on your system, using:
ls /usr/bin/python* Check if any version is configured as a Python alternative or not. Use:
sudo update-alternatives –list python If the output is:
update-alternatives: error: no alternatives for Python It means no alternatives are configured for pythonTo set up all the available versions as alternatives, installed recently, use:
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3.X
(Note: Replace the X with the version you want to install:10 1,.11 2,.12 4)Once configured with the available versions against each other, if you want to change the current one and set some other version as the default one, use:
sudo update-alternatives –config pythonChoose the version you want to set as the default on Ubuntu by entering the number.
Check your Python version again. Use:
python -V
Installing Python 3 on Ubuntu 20.04 or 22.04 is a simple process; by following the steps above in this guide, you can install the latest version of Python and properly configure your system. If you need further assistance, our support team is available to assist 24/7.
If you are having trouble installing Python on Debian 12, read our next tutorial >> How to install Python on Debian 12.