Python is an object-oriented, high-level programming language. It is open source with a large community. Python is used as a key language at top technology companies such as Google.
The stable Python 3.9 release has been published with various improvements and security updates. It includes several new modules, improved existing modules and many other features.
To install Python on an Ubuntu 20.04 system, you can choose the deadsnakes PPA .
Use this tutorial to install Python 3.9 on an Ubuntu 20.04 LTS Linux system via Apt-Get. You can also choose the second method to install Python from source code.
Prerequisites
Log in to your Ubuntu system and open a terminal, then install a few required packages.
sudo apt update
sudo apt install wget software-properties-common
Installing Python 3.9 Using Apt
Use Apt, the Ubuntu package manager, to install Python 3.9 on an Ubuntu Linux system. Follow the steps below
Open a terminal by pressing CTRL + ALT + T, then configure the deadsnakes PPA on your system
sudo add-apt-repository ppa:deadsnakes/ppa
After adding the PPA to your Ubuntu system, update the apt cache and install Python 3.9 on Ubuntu
sudo apt update sudo apt install python3.9
Wait for the installation to finish. Check the Python version by running
python3.9 -V Python 3.9.0
That's it, you have successfully installed Python 3.9 on your Ubuntu 20.04 LTS system.
Installing Python 3.9 from Source Code
You have one more option for installing Python 3.9, which is using the source code. We do not recommend installing Python 3.9 packages from source code. However, in some cases you may need to install Python from source code.
So, follow the instructions below to install Python 3.9 from source code on an Ubuntu 20.04 Linux system.
First, install the packages required to compile the source code. Open a terminal and run the following commands
sudo apt install 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
Now, download the Python 3.9 source code from the official download site. Switch to a suitable directory and use wget to download the source file
cd /opt sudo wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Next, extract the downloaded archive and prepare the source for installation
tar xzf Python-3.9.0.tgz cd Python-3.9.0 sudo ./configure --enable-optimizations
The Python source is ready for installation. Run the make altinstall command to install Python 3.9 on your system
sudo make altinstall make altinstall is used to prevent the default python binary in /usr/bin/ from being replaced.
Python 3.9 has been installed on the Ubuntu 18.04 system. Verify the installed version
python3.9 -V Python 3.9.0
Remove the downloaded archive to free up space
sudo rm -f /opt/Python-3.9.0.tgz