This guide will show you how to install Python 3.9 which is the latest stable version as of this writing. it comes with several improvements and security updates. It also comes with some new modules, improved modules, and many other features.
The target platforms for this guide are Ubuntu, Debian, and Linux Mint distros. In this tutorial, we shall be using Ubuntu 18.04. Python happens to be a very popular open-source, high-level, object-oriented programming language.
We will be showing you two ways on how to install Python 3.9, first using the PPA then we will switch over and show you how to install it from the source. You only need to pick one installation method.
If you would like to install Python on Windows please follow this guide.
Before you install Python 3.9, some required packages will need to be on your system. You can get your system ready by executing the following commands:
$ sudo apt update $ sudo apt install software-properties-common
Install Python 3.9 Using apt-get
In your terminal on your system, execute the following command to add and configure deadsnakes PPA to your system.
$ sudo add-apt-repository ppa:deadsnakes/ppa
Update the apt cache and install Python 3.9 on Ubuntu.
$ sudo apt update $ sudo apt install python3.9
Once complete you can confirm the Python version number by executing the following:
$python3.9 -V Python 3.9.0
Python 3.9 is now installed on your Linux system and ready for general purpose use.
Install Python 3.9 Using Source Code
With the simplicity of installing Python 3.9 on Ubuntu, Debian, and Linux Mint distros, there is very little sense as to why you would want to use the source code to get up and running. Therefore this method is only recommended for power users.
To get started we need to install the essential packages needed to compile the source code. In you terminal execute the following:
$ sudo apt install wget build-essential checkinstall $ sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
Switch to a relevant directory and use wget to download the Python 3.9 source code from the official download site as shown below.
$ cd /opt $ sudo wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Extract the downloaded archive file using tar and configure the source for the installation as shown below:
$ tar xzf Python-3.9.0.tgz $ cd Python-3.9.0 $ sudo ./configure --enable-optimizations
Execute make altinstall command to compile and install Python 3.9 on your Ubuntu system. make altinstall is used to prevent replacing the default python binary file which is located here /usr/bin/python. Instead, it will create python3.9.
$ sudo make altinstall
As always, verify the installed version once the process is complete.
$ python3.9 -V $ Python 3.9.0
You may optionally remove the downloaded archive to free up space.
$ sudo rm -f /opt/Python-3.9.0.tgz
You are now ready to use the latest version of Python together with the default version that came with your Ubuntu, Debian or Linux Mint distros.
Here are some usage examples to test your installation.