This post shows students and new users the steps to install the latest version of Python on Ubuntu Linux from the repository or compile it manually from source code.

Python, a versatile and popular general-purpose programming language, can be easily installed on Ubuntu through multiple methods. Whether you are creating an advanced program or creating a simple task in Python, you will need Python installed in order to use it.

With Python, you can do almost anything, such as writing simple or advanced scripts, building and programming complicated robots and machinery, developing websites, and much more. Python also allows you to work quickly and integrate systems more efficiently.

The latest versions of Python come with many new features including assignment expression, which assigns values ​​to variables as part of a larger expression, position-only parameter, support for f-strings, and many plus.

There are many ways to install Python on Ubuntu. Below are two methods that you can once use to install Python on Ubuntu Linux.

How to install Python from Ubuntu repositories

The fastest way to install Python on Ubuntu is to install it from Ubuntu’s default repositories. Python is available in the default Ubuntu repositories, so all you have to do is simply run the apt get command to install it.

However, the Python versions in the Ubuntu repositories may not necessarily be the latest versions. Ubuntu repositories don’t always have the latest software versions.

To install Python from the Ubuntu repository, run the following commands

sudo apt update
sudo apt install python

After installing Python above, run the following commands to see what versions of Python are installed.

python --version

That should generate a line similar to the following with the version of Python installed. As you can see, the version 2.7.18 it is the current build of Python available on Ubuntu.

Python 2.7.18

How to install Python from source code in Ubuntu

If you want to install the latest versions of Python on Ubuntu, you will want to compile it from source code. Installing Python from source allows you to control which version to install.

Before installing Python from its source code, you must first install some required packages that are required to compile Python from its source code. To install these packages, run the following commands:

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

After installing the packages above, go ahead and download the source code for the latest version of the Python download page using the following wget command.

At the time of writing this article, 3.9.7 It is the latest version of Python. If you find a later version on the site, you can download it instead.

cd /tmp

After downloading the package, run the following commands, extract the file, and install it.

tar -xf Python-3.9.7.tgz
cd Python-3.9.7
./configure --enable-optimizations

Then start the build process with the make command. Replace the #4 with the number of CPU cores in your system for faster build time.

My machine has 4 CPU cores, so I use the make command with -j 4 option.

make -j 4
sudo make altinstall

Don’t use the standard do the installation as it will overwrite the default system with the python3 binary.

After that, the Python version 3.9 it should be installed and ready to use.

To test if the latest version of Python (which is 3.9) is installed and ready to use, run the following commands

python3.9 --version

You should see output similar to the following:

Python 3.9.7

This is how you install Python from source.


In this tutorial we have seen how to install Python on Ubuntu Linux. If you find any errors above or have something to add, please use the comment form below.

Write A Comment