How to Install Python 3 on Ubuntu

install-python3-ubuntu

Python is one of the most widely used programming languages today. It is an open-source language and is used in almost every field of life, including data analysis, web development, artificial intelligence, and many more. One of the most notable features is its cross-platform compatibility. This means Python is available on all major operating systems, including Ubuntu.

Python 2 is old; you should install Python 3. You can easily install Python in Ubuntu via the default repos, the dead snakes PPA, or manually compile the source code. In this tutorial, I will show you three methods to install Python 3 on your Ubuntu-based Linux distribution.

Requirements to Install Python 3 on Ubuntu

You will need to have the following to install Python 3 in the most recent Ubuntu versions:

  • Ubuntu 18.04 or newer
  • sudo/root access
  • Internet connection (for downloading packages or Python source)

How to Check if Python 3 is Installed on Your Ubuntu System?

You can use this terminal command to confirm the availability of Python 3 on Ubuntu:

python3 --version

You will get the output similar to the following if Python is installed on your Ubuntu:

verify python installation

But if it’s unable to be found on your system, then you will receive an error “python command not found“. You can find the full path of your Python bin/installation directory by using the which command as follows:

which python3

It returns the full pathname, for example:

fetch complete python path

How to Install Python in Ubuntu Using APT

Apt is the default package manager for Ubuntu users, which facilitates easy installation of Python 3. Though it does not always provide the most recent Python version that is available on Python. org. Here’s how to install Python 3 on Ubuntu using apt in a few easy steps:

Step 1: Update and Upgrade Package Repository

As usual, before you install anything, start by refreshing your system’s package list. That way, you’ll get the freshest answer on what software and updates are to be had. Let’s now refresh the package list and upgrade all packages to prevent clashes during installations:

sudo apt update && sudo apt upgrade -y

Step 2: Install Python on Ubuntu

Now, when you have your package list updated, you can install Python on your Ubuntu. Here’s what you have to do to be able to run that command:

sudo apt install python3
install python 3 using apt

Step 3: Verify Installed Python 

After installation is finished, confirm the Python version is correctly installed on your system:

python3 --version
verify python installation

How to Install Python 3 Through PPA

PPAs are external software repositories that developers make for Ubuntu users to be able to install newer versions of programs that are not available in the official repositories. Adding a PPA allows you to use a new feature or bugfix ahead of anyone else in Ubuntu. It’s useful for keeping up to date with the tools you’re using.

Step 1: Update Repository Lists

Now run the command below to update the lists of packages available from repositories:

sudo apt update && sudo apt upgrade -y

Step 2: Install Necessary Tools

If you want to handle software sources more comfortably, then install the software-properties-common package. It enables you to add PPA repositories to the system. You can install it using the following command:

sudo apt install software-properties-common
 Install Necessary Tools

Step 3: Add the Deadsnakes PPA

Deadsnakes PPA includes newer versions of Python that we can install in the Ubuntu default repository. For the updated versions, you can add the Deadsnakes PPA. Open a terminal (Ctrl+Alt+T) and run the following:

sudo add-apt-repository ppa:deadsnakes/ppa

Hit Enter to continue, and then refresh the package repository.

add deadsnakes ppa

Then upgrade your package list to follow the latest version of Python like this:

sudo apt update

Step 4: Install Python3 on Ubuntu

The Deadsnakes PPA provides many different versions of Python, both for Ubuntu versions & Zope. You can select the version you want to install by including it in the package name.

For instance, to install the latest version, Python 3.12, you can execute the command:

sudo apt install python3.13
install python 3 ubuntu using ppa

Step 5: Confirm Python3 Installation

 Now, to check if Python3 is installed. Now, check the installation of the latest Python 3 version, with the following command:

python3 --version

How to Install Python 3 on Ubuntu From Source

This way enables you to download and compile Python directly from the official source code. It’s slightly more advanced but provides you with the most recent version of Python available, which you can’t get through package managers.

Step 1: Update Local Repositories

Update your local repositories with this command:

sudo apt update

Step 2: Install Required Tools

In order to compile Python from source, your system must have certain additional tools and libraries. Here are some of these that are useful for compiling and installing software properly. Run the following to install all required packages.

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

Step 3: Download the Latest Python Source Code

First, try visiting the /tmp directory using the command below. It is where you are supposed to use for transient files, and therefore this would be the place to download and install software, and not clog your system:

cd /tmp

Then, go to the official Python website and the Downloads page. Select the one you would like to install, scroll down to the “Files” section, and copy the link to the Gzipped source tarball (it will be a file ending in .tgz or .tar.gz):

copy installation link

Now, you can download the latest Python source code using the wget command and the copied link:

wget https://www.python.org/ftp/python/3.13.5/Python-3.13.5.tgz
download the latest Python source

Step 4: Unpack the Downloaded File

Now, extract the .tgz file you downloaded using the command below:

tar -xf Python-3.13.5.tgz

Be certain to use the same version number that you downloaded in the file name. This command won’t display a message after it is executed:

extract downloaded tar file

Step 5: Prepare and Optimize Python for Installation

Prior to the installation of Python, be sure the system configuration and performance are in place. First, navigate to the directory where you extracted, and then run:

cd Python-3.13.5
./configure --enable-optimizations

It inspects your system and configures the build process for Python. If the Python you get is built with the “–enable-optimizations” option, it enables the Python binary to run a bit faster (10–20% increase in performance). This step will take a while, so be patient and allow it to be fully completed:

Prepare and Optimize Python for Installation

Step 6: Install Python

When you have configured and optimized Python, initiate the compilation of the package with:

sudo make install
install python source code

And finally, run the command “python –version” to verify Python is appropriately set up on your system:

python --version
confirm python installation

Conclusion

There are several ways you can install Python 3 on Ubuntu, from using the native package manager to a simple one-click download. The simplest way is how most users will want to do it, with the APT package manager. Adding the Deadsnakes PPA is an excellent alternative if you want a newer version. If you like living on the edge and want to run the very latest, you can compile Python from source. We have walked you through how to install Python 3.

Choosing a VPS provider can be a difficult task, with so many options available. Ultahost understands your specific needs and requirements and brings you a perfect solution. Get access to Ultahost’s best free VPS servers with a free trial, ensuring ultra-fast speeds and instant deployment. Choose between Linux and Windows and host your websites or applications at any of our 20+ global data centers.

FAQ

What is the easiest way to install Python 3 on Ubuntu?
How can I check if Python is already installed on my Ubuntu system?
Why should I use the Deadsnakes PPA to install Python?
What’s the benefit of installing Python from source?
Can I install multiple Python versions on Ubuntu?
Does Ubuntu ship with Python already installed?
How can I uninstall an old Python version on Ubuntu?

Related Post

How to Enable or Disable IPV6 on Ubuntu Linux

IPv6, also known as Internet Protocol version 6, offers...

How to Install FFmpeg on Ubuntu 22.04

As a Ubuntu user, managing video and audio files can be...

How to Install ELK Stack on Ubuntu

The ELK Stack, comprising Elasticsearch, Logstash, and ...

How to Enable Ubuntu Remote Desktop

Remote desktop allows you to manage your system remotel...

How to Install SQLite on Ubuntu 22.04

As a system administrator or developer, you are likely ...

How to Install Elasticsearch on Ubuntu

Elasticsearch is a powerful open-source search and anal...

Leave a Comment