How to Upgrade Python on Linux

Estimated reading: 2 minutes 376 views

Python is a popular programming language. Like many other programming languages, there can be several different versions organized by release date. Certain applications may require a specific version of Python.

This article we uses Ubuntu and its APT package manager to upgrade Python. If you are using a different Linux distribution, replace the apt Linux command with the appropriate command featured for your package manager. We will guide you to upgrade to Python3.9 in this article

Upgrade Python

1. Start by update the repositories:

apt update

2. Next, install Python 3.9 by running:

apt install python3.9

When prompted, type Y to start the installation.

3. Once Python installs, invoke the 3.9 version by running:


4. However, checking the installation with the python3 --version command still returns the old version. To fix this, you need to create a list of update alternatives. First, add the old version to the list with the command:

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1

5. Now add the new version:

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

6. Next, type the following command to configure the priority status of the versions:

update-alternatives --config python3

The output displays the available choices and their assigned number (in the example below, the numbers are 012). Type the number of the the version you wish to use and press Enter.

7. If you are not planning to use the old version of Python, remove the symlink that contained the previous Python 3 version with:

rm /usr/bin/python3

8. Then, replace the symlink with the new version:

ln -s python3.9 /usr/bin/python3

9. Now, check the default version:

python3 --version

The output should confirm the successful installation and setup of the latest available version.


Since Python 3 was not a backward-compatible release, for a long time Python 2 remained the version of choice for those who wanted a stable development environment.

However, given that the official support for the final Python 2.7 release has ended, upgrading to Python 3 is now strongly recommended. Python 3 is faster, and its syntax is more user-friendly.

If you already work with Python 3, upgrading to the latest point release gives you all the security updates and bug fixes.

After reading this tutorial, you should know how to upgrade your Python 3 version on Linux.

Leave a Comment