Python is typically pre-installed in Ubuntu, but if it isn't, you may easily install it in Ubuntu by following a few simple steps. 

Python is necessary if you're a developer and want to create various programs and websites. 

Apart from that, Python is a critical component of the Ubuntu software stack; therefore, having it is essential to the OS's proper operation. Let's go on to learning how to install Python in Ubuntu now.

Install Python using APT.

The default package manager on Ubuntu is called APT, or Advanced Package Tool. The Python package is available for download from the official Ubuntu repository.

Python is installed by this approach using the apt package manager. There are fewer processes, but they are subject to revisions to third-party hosting software. On a third-party repository, new releases might not appear as rapidly.

Python is typically pre-installed in Ubuntu 18.04 or Ubuntu 20.04 factory versions. Enter the following to check the Python version you are using:

python –version

Continue to the next step if Python is not installed or the revision level is less than 3.7.x.

Update and refresh repository lists 

To start, launch a terminal window and type the following:

sudo apt update

Installing supporting software 

By enabling you to add PPA (Personal Package Archive) repositories, the software-properties-common package gives you increased control over your package management. 

Use the following command to install the additional software:

sudo apt install software-properties-common

Include Deadsnakes PPA

A PPA called Deadsnakes has more recent releases than the standard Ubuntu repository. Enter the following information to add the PPA:

sudo add-apt-repository ppa:deadsnakes/ppa

You will be asked to press enter to proceed with the system. Do that and let it finish. Update the package listings once more:

sudo apt update

Download the latest version of Python

Use the following code in this step:

sudo apt install python3

Your computer will automatically locate the package and install it, thanks to APT.

You can ensure that the Python version was successfully installed with this code:

python –version

Install Python in Ubuntu from Source Code

The most recent version of Python is also available for download and building from the official Python website. 

Even if you initially find compiling the source code a little intimidating, it gets simpler after you know how to do it.

Update Local Repositories

Use this command to update local repositories:

sudo apt update

Install additional software

A package must have additional software to be compiled from the source code.

To install the necessary packages for Python, type the following:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Download Python Source Code's most recent version

Navigate to the /tmp directory and then use the wget command to get the most recent version of the Python source code:

cd /tmp


Extract the compressed files.

The tgz file you downloaded must then be extracted using the following command:

tar -xf Python-3.8.3.tgz

System testing and Python optimization

Make sure to test the system and optimize Python before you install Python in Ubuntu.

Python is evaluated and made ready for installation on your system using the./configure program. Code execution is accelerated by 10–20% when the —optimization option is used.

Put the following in:

cd python-3.8.3

./configure --enable-optimizations

It may take you up to 30 minutes to finish this stage.

Installing a second instance of Python (recommended)

Add the following to your current Python installation to create a second Python 3.835 installation:

sudo make altinstall

You should employ the altinstall technique. Software packages on your Ubuntu system can depend on Python 2.x.

Python version check

Put the following in:

python3 --version

Keep in mind that PIP is used to manage Python modules. The Python Package Index can be downloaded and added using the package management tool PIP. 

If you wish to include extra modules in your next Python project, installing Python PIP on your computer is critical.

Updating to the most recent version of Python

Ensure Python isn't installed on your system with an older version first. Entering the python3 —version in your terminal will allow you to do this. Take note of the version information.

By searching on the internet, you can learn what the most recent version is. Just do a fast Google search for "python newest version number." You probably use an old version if the two numbers don't align.

The Advanced Package Tool in Ubuntu makes it simple to update to the most recent version of Python. 

If you used APT or the Deadsnakes PPA to install Python on your computer, do the following command to get the most recent version of the language:

sudo apt install python3

The —only-upgrade flag can also be used to update your packages.

sudo apt --only-upgrade install python3

For individuals who have independently constructed Python from source code, you can visit the Python FTP and get the most recent version. To build the package, you must repeat all of the procedures.

Using various Python versions

If you installed Python using the altinstall technique, your system runs two different Python versions simultaneously. Every installation uses a unique command.

To execute instructions for any older Python 2.x version on your system, use the Python command. For instance:

python --version

Use python3 to execute a command in the more recent version. For instance:

python3 –version

Multiple major Python versions (3.x or 2.x) may exist on your machine. If you have both Python 3.7.x and Python 3.8.x installed, you can choose which version to use by using the second digit:

python3.7 --version

python3.8 --version


Almost all Linux systems come with Python preinstalled, and it is also accessible through official distribution repositories. 

The Ubuntu package management makes it simple to download Python if you still don't have it set up on your computer.

The Python language is employed in many industries, and its applications show its effectiveness. Due to the increasing demand for developers across industries, programming languages have now taken on a crucial role.

Following this article's steps, you can easily install Python in Ubuntu. 

People also read: