Python is a widely used programming language in software development, web development, data analysis, and machine learning. Ubuntu provides a powerful platform for Python developers. In this article, we will explain how to install Python on Ubuntu 22.04 and get started with programming.
Table of Contents
Follow the same procedure for all Ubuntu-based distributions including PopOS, Kubuntu, Linux Mint, and Elementary OS.
How to Check if Python3 is Installed?
Python 3 is included by default in Ubuntu 22.04. To determine the Python version on your system, enter:
python3 --version
The output should be like the following:
Python 3.10.6
If you require another or many Python versions on your system, you should build them from source.
Installing Python on Ubuntu from Source
Compiling Python from source allows you to install the most recent Python version and customize the build parameters. However, you will be unable to maintain your Python installation using the apt package manager.
Python is 3.11 is the most recent version of the most recent major release. This version incorporates several performance improvements and new features, such as new standards library modules, new syntax, and built-in capabilities, and more.
The instructions below describe how to compile Python 3.11 from source. Change the version number in the commands below if installing a newer release.
1. First, install the libraries and dependencies required to build Python:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
2. Using the wget
command, get the current release’s source code from the Python download page:
wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
3. Once the download is complete, extract the archive as follows:
tar -xf Python-3.11.3.tgz
4. Open the Python source directory and execute the configure command. This script runs a series of tests to ensure that all dependencies are present on your system:
cd Python-3.11.3
./configure --enable-optimizations
The --enable-optimizations
option allows the Python binary to be optimized by running multiple tests. This slows down the building process.
5. Start the build process:
make -j 12
To reduce build time, change the -j
to the number of cores in your processor. By entering nproc
, you may find the number of cores in your system.
6. Once the build is finished, install the Python binaries by typing:
sudo make altinstall
We’re using altinstall
instead of install
since the later command would replace the system’s default python3 binary.
That’s it. The latest Python has been installed on your system and is ready to be used by executing python3.11
. To verify it, type:
python3.11 --version
The output will show the Python version:
Python 3.11.3
You can also read how to install PHP 8.2 on Ubuntu 22.04
This article is to help you learn about how to install Python on Ubuntu 22.04. We trust that it has been helpful to you. Please feel free to share your thoughts and feedback in the comment section below.