Follow
Ubuntu Linux

How to Install Python on Ubuntu Linux

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

You install Python on Ubuntu Linux by using either the default package repositories or by compiling it directly from the source code.

Python is a powerful, interpreted, high-level programming language widely used for web development, data science, artificial intelligence, and more. Installing it on your Ubuntu system unlocks its vast capabilities.

This guide shows you how to get the latest Python 3.10 version running on your Ubuntu 22.04 LTS system, ensuring you have a robust development environment.

You can easily install Python using simple commands from Ubuntu’s official repositories, or for more control, you can compile it yourself from the Python source code.

⚡ 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`.

How to install Python from Ubuntu repositories

The quickest way to install Python on Ubuntu is from Ubuntu’s default repositories. Python is available in Ubuntu default repositories, so all one needs to do is simply run the apt-get command to install it.

However, the versions of Python in Ubuntu repositories may not necessarily be the latest. Ubuntu repositories do not always have the latest software builds.

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

🐧Bash / Shell
sudo apt update
sudo apt install python

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

💻Code
python --version

That should output a similar line as below with the version of Python installed. As you can see, version 2.7.18 is the current build of Python available in Ubuntu.

💻Code
Python 2.7.18

How to install Python from source code on Ubuntu

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

Before installing Python from its source code, you must install some required packages to build it from the source. To get these packages installed, run the commands below:

🐧Bash / Shell
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 above packages, download the latest release’s source code from the Python download page using the following wget command.

When writing this post, 3.9.7 is the latest Python version. If you find a later version on the site, you can download it instead.

Command Prompt
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.

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

Next, start the building process using the make command. Replace #4 with the number of CPU cores on your system for faster build time.

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

🐧Bash / Shell
make -j 4
sudo make altinstall

Please do not use the standard make install, as it will overwrite the default system with the python3 binary.

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

💻Code
python3.9 --version

You should see an output similar to the one below:

💻Code
Python 3.9.7

That’s how you install Python from its source

Conclusion:

This post showed you how to install Python on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.

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.

📚 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 *