This article will show you how to update Python to the latest version on your Linux Operating system.
Python is updated yearly with new features and big upgrades – these are called major updates. In addition to this, monthly updates are released which fix small issues and improve security – these are called minor updates.
Major updates change how Python works a bit and may break compatibility with some code as features are added or removed, whereas minor updates are solely there to fix problems without altering any functionality.
Updating From Python 2 to Python 3
There are two commonly used flavors of Python – Python 2 and Python 3.
Python 3 is still actively developed, receiving both minor and major updates. Python 2 is obsolete – it’s no longer developed, and you shouldn’t be using it for any new projects or to learn.
If you’re upgrading from Python 2 to Python 3, you will need to check your code is compatible – the syntax differs slightly between the two.
Python 2 and Python 3 are treated as separate software packages by most Linux package managers. To upgrade to version 3, simply install it.
The rest of this article will focus on the actively developed Python 3 only.
Install the Latest Version of Python on Ubuntu/Debian
On Ubuntu/Debian based distributions (including Mint, PopOS, etc) – run the following command:
sudo apt install python3
This will install the default Python 3 version currently available on Ubuntu.
To install a specific version of Python 3, specify the full version:
sudo apt install python3.9
Install the Latest Version of Python on Fedora/RHEL
To install Python on RedHat based operating systems, run the following:
sudo dnf install python39
Note that the major version of Python 3 is always specified when installing using the dnf package manager – in this case, Python 3.9
Checking What Version of Python is Currently Installed
To check which version of Python you have installed, run:
Using a Package Manager to Upgrade Python Version
If Python 3 is already installed on your system, it will be updated along with the rest of your system when a software update is run.
sudo apt-get update sudo apt-get upgrade
sudo dnf upgrade --refresh
Updating Minor/Major Versions
On Ubuntu/Debian based systems, Python will update to the default version available via the package manager. This is usually a bit behind the official release but is considered stable. This may include major releases if you have installed via the python3 package rather than a specific version.
On Fedora, only minor updates will be applied – you’ll need to install the next major release manually when it is available.