Ubuntu Linux

How to Install Python on Ubuntu Linux

Richard
Written by
Richard
Sep 26, 2021 Updated Mar 18, 2026 4 min read
How to Install Python on Ubuntu Linux

This post shows students and new users the steps to install the latest version of Python on Ubuntu Linux from the repository or manually build it from the source code.

Python, a versatile and popular general-purpose programming language, can easily be installed on Ubuntu via multiple methods. Whether you’re building an advanced program or creating a simple task in Python, you’ll need Python installed to use it.

With Python, you can write simple or advanced scripts, build and program robots, complicated machinery, develop websites, and many more. Python also lets you work quickly and integrates systems more efficiently.

The latest versions of Python come with many new features, including assignment expression — which assigns values to variables as part of a larger expression, position-only parameters, f-strings support, and many more.

There are many ways to install Python on Ubuntu. Below are two methods one can use to install Python on Ubuntu Linux.

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.

Frequently Asked Questions

How do I install Python on Ubuntu?

You can install Python on Ubuntu by using the default repositories. Simply run the commands 'sudo apt update' followed by 'sudo apt install python' in your terminal.

What is the latest version of Python available for Ubuntu?

The latest version of Python available for Ubuntu may vary. As of now, you can check the official Python website for the most recent release, which is often newer than the version available in the Ubuntu repositories.

Can I install Python from source code on Ubuntu?

Yes, you can install Python from source code on Ubuntu. This method allows you to choose the specific version you want to install, and involves downloading the source code, extracting it, and running the build commands.

What packages do I need to install Python from source on Ubuntu?

To install Python from source on Ubuntu, you need to install several required packages. Run 'sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev' to get started.

How can I check the installed version of Python on Ubuntu?

After installing Python, you can check the installed version by running the command 'python --version' in the terminal. This will display the current version of Python that is installed on your system.

Was this guide 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.

2473 articles → Twitter

📚 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
Change Power Button Behavior in Ubuntu Linux
Ubuntu Linux Change Power Button Behavior in Ubuntu Linux
Add Multiple Clocks to Ubuntu Linux Top Bar
Ubuntu Linux Add Multiple Clocks to Ubuntu Linux Top Bar

Leave a Reply

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