How to Install Python on Ubuntu Linux
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. For modern apps you need a complete setup, with the built-in terminal and the package manager working properly.
Before you install anything, open your terminal and check which version you already have. Ubuntu 22.04 ships Python 3.10 as python3, and Ubuntu 24.04 ships 3.12, so your system may already be recent enough. If it is not, or you need a specific release, use one of the two methods below. You need an account with sudo rights and a working internet connection for both.
Open a terminal and run sudo apt update, then sudo apt install python3 to install Python from the Ubuntu repositories. Check the result with python3 –version. Ubuntu 22.04 ships Python 3.10 and Ubuntu 24.04 ships 3.12, so you may already have a recent version. For the newest release, build Python from source instead.
How to install Python from Ubuntu repositories
Installing Python from the Ubuntu repositories is the fastest method. The built-in package manager downloads and sets up Python for you. You update your package list first, then run one install command in the terminal. The version you get is whatever Ubuntu ships for your release, which is usually not the newest one. It also receives security updates through normal system updates.
Run the command below to install Python from the default repository. Type your password when asked. Nothing shows on screen while you type it, which is normal. When the prompt returns, the installation is finished. Then verify the version with:
sudo apt update sudo apt install python3
After installing Python above, run the commands below to see which versions of Python are installed. Ubuntu can hold more than one version side by side, so this tells you exactly what the system sees.
python3 --version
That should output a line similar to the one below, showing the installed version of Python. In this example, version 2.7.18 is the build the Ubuntu package provided. Your number may differ depending on your Ubuntu release and which package you installed. If you see a different version, that is fine as long as the command runs without an error.
Python 3.10.12
How to install Python from source code on Ubuntu
Installing Python from source code gives you access to the newest releases and lets you pick your own setup options. The trade-off is time and manual upkeep. The build takes several minutes, and Ubuntu will not update this copy for you. You start by installing a few compiler tools and libraries so your computer can build the Python files from scratch.
Two examples are `build-essential`, a collection of tools for compiling software, and `zlib1g-dev`, which handles compressed data. Run the commands below to install these build packages before you build Python. If a package is missing, the build can still finish, but some Python modules will be left out. Installing the full set first avoids that.
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. The download is a compressed archive, so it may take a moment depending on your connection.
The version number in the commands below is only an example. Substitute it with whichever release you downloaded, in both the file name and the folder name. A wrong number is the most common cause of a "No such file or directory" error at this point.
cd /tmp wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz
After downloading the package, run the commands below. They extract the archive and prepare the build in the extracted folder. This step checks your system for the tools and libraries you installed earlier. When it finishes without errors, you are ready to compile.
To build Python on Ubuntu Linux, use the `make` command followed by the number of CPU cores your system has. In the example, replace `#4` with your own core count. Using this number speeds up the build significantly, because the work is split across all cores. Expect a lot of text to scroll past. This is normal, and the build is done when the prompt returns.
For example, if your machine has 4 CPU cores, use `make -j 4`.
It would replace the existing `python3` binary with your new build. Ubuntu tools that depend on the system Python could then break. Use the install command in the next block instead. It installs the new version alongside the system one, under its own version-numbered name.
After that, Python version 3.9 should be installed and ready to use. Your original system Python stays untouched. Because the new copy has a version-numbered name, you start it by typing that full name, not plain python3.
To test that the latest version of Python (3.9 in this guide) is installed and ready to use, run the commands below. Use the version number that matches the release you built.
python3.9 --version
You should see an output similar to the one below. If you get "command not found" instead, check that the version number you typed matches the one you built, and that the install command in the previous step finished without errors.
Python 3.9.7
That covers installing Python from its source. Once it is built, you can delete the downloaded archive and the extracted folder to free disk space. The installed copy does not need them.
Conclusion:
This guide showed two ways to install Python on Ubuntu Linux. The repository method is quick and gets security updates through Ubuntu. Building from source gives you a newer release without touching the system Python. If you hit an error or have something to add, use the comment form below the article.
Have a question about this guide?
Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.
Did this guide fix your problem?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
No comments yet — be the first to share your thoughts!