How to Install Python 3 on Ubuntu 20.04 or 22.04

July 18, 2024 / General Discussion

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.

  1. Start with the Ubuntu Update:
    First, ensure you have the latest package updated in your system:
    sudo apt update
  2. 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
  3. 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
  4. 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

  5. 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.)
  6. 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 python

    To 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 python

    Choose 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.

Leave a Reply

Your email address will not be published. Required fields are marked *