The latest version of Python is 3.9.2 on the date of posting this tutorial that shows how to install Python on Ubuntu.

Installing Python 3.9 on Ubuntu with Apt

Installing Python 3.9 on Ubuntu with apt is a relatively straightforward process and takes only a few minutes to complete.

  1. Update the packages list and install the prerequisites:
    sudo apt updatesudo apt install software-properties-common
  2. Add the deadsnakes PPA to your system’s sources list:
    sudo add-apt-repository ppa:deadsnakes/ppa
    When prompted, press [Enter] to continue.
  3. Once the repository is enabled, you can install Python 3.9 by executing:
    sudo apt install python3.9
  4. Verify that the installation was successful by typing:
    python3.9 --versionPython 3.9.1+

That’s it. Python 3.9 is installed on your Ubuntu, and you can start using it.

Installing Python 3.9 on Ubuntu from Source

Compiling Python from the source allows you to install the latest Python version and customise the build options. However, you won’t be able to maintain your Python installation through the apt package manager.

The following steps explain how to compile Python 3.9 from the source:

  1. Install the dependencies necessary to build Python:
    sudo apt update
    sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
  2. Download the latest release’s source code from the Python download page with wget :
  3. Once the download is complete, extract the gzipped archive :
    tar -xf Python-3.9.2.tgz
  4. Switch to the Python source directory and run the configure script, which performs a number of checks to make sure all of the dependencies on your system are present:
    cd Python-3.9.2
    ./configure --enable-optimizations

    The --enable-optimizations option optimises the Python binary by running multiple tests. This makes the build process slower.
  5. Start the Python 3.9 build process:
    make -j 12
    For faster build time, modify the -j to correspond to the number of cores in your processor. You can find the number by typing nproc.
  6. When the build process is complete, install the Python binaries by typing:
    sudo make altinstall
    We’re using altinstall instead of install because later will overwrite the default system python3 binary.

That’s it. Python 3.9 has been installed and ready to be used. To verify it, type:

python3.9 --version

The output should show the Python version:

Python 3.9.1


Python 3.9 is not available in the standard Ubuntu 20.04 repositories.

We’ve shown you how to install Python 3.9 on your 20.04 machine. You can now start developing your Python 3.9 project.

Source from: Linuxize

Leave a Reply

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

Post comment