Or copy link
Copy link
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.
You will need to have the following to install Python 3 in the most recent Ubuntu versions:
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:
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:
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:
Experience Ultahost’s Top-tier Python Hosting!
Experience top-tier Python hosting, optimized for developers with seamless integration and superior performance for your projects.
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
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
After installation is finished, confirm the Python version is correctly installed on your system:
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.
Now run the command below to update the lists of packages available from repositories:
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
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.
Then upgrade your package list to follow the latest version of Python like this:
sudo apt update
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
Read also How to Install NumPy using Python.
Now, to check if Python3 is installed. Now, check the installation of the latest Python 3 version, with the following command:
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.
Update your local repositories with this command:
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
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):
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
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:
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:
When you have configured and optimized Python, initiate the compilation of the package with:
sudo make install
And finally, run the command “python –version” to verify Python is appropriately set up on your system:
python --version
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.
The quickest way is to run sudo apt install python3 in the terminal and let the package manager do the rest.
Open a terminal and type “python3 –version”. If Python is present, you will see the version number. If it is missing, you will get a command not found message.
The Deadsnakes PPA often has newer Python builds because the official Ubuntu archive can lag behind. Using it means you get fresh features and bug fixes sooner.
Building Python from source lets you grab the absolute latest release and tweak compile flags for performance, which can make your code run a bit faster.
Definitely; you can have Python 3.10, 3.12, and 3.13 all installed at once by using PPAs or compiling manually, then you pick the one you need with update-alternatives or a virtual environment.
Yes, nearly every version of Ubuntu has Python 3 on board from the first boot, though you might later want to upgrade it or grab a special build for your project.
Run “sudo apt remove python3.x” through the terminal, but take care, as a few essential system utilities still rely on that interpreter.
IPv6, also known as Internet Protocol version 6, offers...
As a Ubuntu user, managing video and audio files can be...
The ELK Stack, comprising Elasticsearch, Logstash, and ...
Remote desktop allows you to manage your system remotel...
As a system administrator or developer, you are likely ...
Elasticsearch is a powerful open-source search and anal...
Save my name, email, and website in this browser for the next time I comment.
Δ