How to Install Python on Ubuntu Linux
You install Python on Ubuntu Linux using either the default package repositories or by compiling from source code.
Python is a versatile, high-level programming language essential for tasks ranging from web development to data science. Installing it on your Ubuntu system empowers you to leverage its extensive libraries and frameworks.
This guide walks you through installing Python 3.10 on Ubuntu 22.04 LTS. This ensures you have a stable and up-to-date version ready for your projects.
You can choose the simpler method of using Ubuntu’s official repositories, or opt for compiling from source for greater customization and access to the absolute latest releases.
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
Installing Python from Ubuntu’s default repositories is the quickest method, using a simple command to get it running on your system.
To install Python from the Ubuntu repository, run the commands below
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. As you can see, version 2.7.18 is the current build of Python available in Ubuntu.
Python 2.7.18
How to install Python from source code on Ubuntu
To get the absolute latest Python versions on Ubuntu, you can install it by building from the source code, which gives you full control over the version.
Before installing Python from its source code, you must install some required packages to build it. To get these packages installed, run the commands below:
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.
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.
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.
tar -xf Python-3.9.7.tgz cd Python-3.9.7 ./configure --enable-optimizations
Next, start the building process using the `make` command. You’ll see `#4` in the `make` command. Replace that number with how many CPU cores your system has; this speeds up the build process.
For example, if your machine has 4 CPU cores, you’d use `make -j 4`.
make -j 4
sudo make altinstallPlease 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
python3.9 --version
You should see an output similar to the one below:
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?
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.
No comments yet — be the first to share your thoughts!