Skip to content
Follow
Ubuntu Linux

How to Install Python on Ubuntu Linux

Richard
Written by
Richard
Sep 26, 2021 Updated Sep 15, 2026 3 min read
Enable Automatic Suspension in Ubuntu Linux Easily
Enable Automatic Suspension in Ubuntu Linux Easily

Python is a programming language you use to build websites, run scripts, and automate daily tasks on your computer. Ubuntu 22.04 LTS and newer versions often include an older build, but you need a complete setup with the built-in terminal and package manager to run modern apps.

Advertisement

Open your terminal and check your current version to start installing the newest release on your system.

⚡ Quick Answer

You can install Python on Ubuntu using apt commands or by compiling from source. Run `sudo apt update` and `sudo apt install python` for the repository method. For the latest version, download the source code, extract it, and use `make -j 4` followed by `sudo make altinstall`.

Advertisement

How to install Python from Ubuntu repositories

Installing Python from Ubuntu repositories is the fastest way to add Python to your system using the built-in package manager. You just need to update your package list and run a quick terminal command to download and set up Python automatically.

Run the command below to install Python from the default repository. Once the installation finishes, verify the version with:

sudo apt update
sudo apt install python

After installing Python above, run the commands below to see which versions of Python are installed.

python --version

That should output a similar line as below with the version of Python installed. Version 2.7.18 is the current build of Python available in Ubuntu.

Advertisement
Python 2.7.18

How to install Python from source code on Ubuntu

Installing Python from source code on Ubuntu gives you access to the newest releases and lets you pick your own setup options. You start by installing a few essential compiler tools and libraries so your computer can build the Python files from scratch.

Ubuntu 22.04 requires specific packages, such as `build-essential` (a collection of tools for compiling software) and `zlib1g-dev` (for handling compressed data), to compile Python from source code. Run the commands below to install these build packages before you install Python from its source code.

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 those packages, download the latest release's source code from the Python download page using this `wget` command.

Substitute the version number in the commands below with whichever release you downloaded.

Advertisement
cd /tmp
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz

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

To begin building Python on Ubuntu Linux, use the `make` command followed by the number of CPU cores your system possesses. For example, instead of `#4`, enter your system's core count. Using this number significantly speeds up the Python build process.

For example, if your machine has 4 CPU cores, use `make -j 4`.

To avoid overwriting the default system Python, do not use the standard `make install` command. This command would replace the existing `python3` binary with your new installation.

Advertisement

After that, Python version 3.9 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 commands below

python3.9 --version

You should see an output similar to the one below:

Python 3.9.7

That covers installing Python from its source.

Advertisement

Conclusion:

This guide explains Python installation on Ubuntu Linux. Users can report errors or share additional information using the comment form provided below the article.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

How to Install Python Pip on Ubuntu Linux
Ubuntu Linux How to Install Python Pip on Ubuntu Linux
How to Install Let's Chat on Ubuntu Linux
Ubuntu Linux How to Install Let's Chat on Ubuntu Linux
Add Multiple Clocks to Ubuntu Linux Top Bar
Ubuntu Linux Add Multiple Clocks to Ubuntu Linux Top Bar
How to Change Screen Brightness in Ubuntu Linux
Ubuntu Linux How to Change Screen Brightness in Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *