Python is an object-oriented, high-level programming language. It is open-source with a large community. Python is used as a key language among the top tech companies like Google.
The latest stable version Python 3.9 is out with several improvements and security updates. It included multiple new modules, improved existing modules and many other features.
This tutorial will help you to install Python 3.9 on Ubuntu 18.04 LTS system. This method will use Python’s source code for the installation.
Follow the below tutorial and choose one method to install Python 3.9. Both the methods are tested with the latest Ubuntu 18.04 system.
Before beginning the Python installation, install some required packages on your system. Login to your Ubuntu system and execute following commands:
sudo apt update
sudo apt install software-properties-common
Install Python 3.9 Using Source Code
As the Debian packages are available, We don’t recommend installing Python 3.9 packages from source code. But in some cases, you may need to install Python from the source code.
So follow the below instructions to install Python 3.9 using source code on Ubuntu 18.04 Linux system.
- First of all, install essential packages for compiling source code. Open a terminal and execute following commands:
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
- Now, download the Python 3.9 source code from the official download site. Switch to a relevant directory and use wget to download the source file.
sudo wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
- Next, extract the downloaded archive file and prepare the source for the installation.
tar xzf Python-3.9.16.tgz
sudo ./configure --enable-optimizations
- Python source is ready to install. Execute make altinstall command to install Python 3.9 on your system.
sudo make altinstall
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
- The Python 3.9 has been installed on Ubuntu 18.04 system. Verify the installed version:
python3.9 -VPython 3.9.16
- Remove the downloaded archive to free space
sudo rm -f /opt/Python-3.9.6.tgz
In this tutorial, we have demonstrated two different methods for installing Python 3.9 on Ubuntu 18.04: using the source archive file and APT PPA. Each approach has its merits, with the source archive file offering a more tailored installation experience, while the APT PPA method provides ease and efficiency. By following the steps outlined in this guide, you can now take advantage of Python 3.9’s latest features and performance enhancements. As you progress in your Python endeavors, make sure to explore the vast array of libraries and frameworks available to further improve your programming capabilities and optimize your projects. With Python 3.9 installed on your Ubuntu 18.04 system, you are well-prepared to address various programming challenges and develop innovative, high-performing applications.