How to Install|Upgrade Python 3.10 on Ubuntu 22.04|20.04 ✅

Posted April 4, 2024
How to Install|Upgrade Python 3.10 on Ubuntu 22.04|20.04

This guide teaches you to install a specific Python version 3.10 on your Ubuntu 22.04|20.04. Almost every Ubuntu OS has Python installed. However, at times, you need to get an opinionated version of your choice. In this case, installing Python 3.10 on your Ubuntu LTS.

Along this tutorial, you will:

  • How to install Python version 3.10 on Ubuntu from Python source code.
  • Installing Python 3.10 using PPA deadsnakes on Ubuntu.
  • Exploring the alternative to using Pyenv to manage different Python versions

Ready? Dive in and Install Python 3.10 on Ubuntu 22.04|20.04 in this magic guide.

Prerequisites to Installing Python 3.10 on Ubuntu

To get Python 3.10 ready on Ubuntu, you will need:

  • A sudo privileged Ubuntu terminal.
  • Internet connections and basic understanding of Ubuntu 22.04|20.04.

Related: How to Update and Upgrade Python3 Version on Ubuntu 22.04|20.04

Installing Python 3.10 on Ubuntu from Source

Python has traces of all stable Python versions. This means you can pull your specific version and get installed on your Ubuntu machine. Going by this, you can easily access Python Source and get Python 3.10 installed on Ubuntu:

Installing Python 3.10 on Ubuntu

Now, you will need to use the Ubuntu wget command to get your specific version. Here are the steps you need to get this ready:

  • First, ensure you have the Ubuntu package index updated:
# Get package update list
sudo apt update
# upgrade the packages
sudo apt upgrade -y
  • Before installing Python, ensure you have these necessary packages available for Ubuntu Python 3.10:
sudo apt install -y zlib1g-dev build-essential libncurses5-dev libnss3-dev \
    libgdbm-dev libssl-dev libffi-dev libreadline-dev

Preparing Python 3.10 on Ubuntu

Next, grab your specific Python version, In this case, Python 3.10, and let Ubuntu download this version from the source using wget:

But Note: Python 3.10 must include the exact semantic version of Python 3.10 you want to download. For example, 3.10.0, 3.10.1, 3.10.2, 3.10.3, 3.10.4, 3.10.5, 3.10.12, 3.10.14. In this case, I will install the most recent Python 3.10 version, which is 3.10.14. This way, the wget command will be as follows:

wget https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz

Installing Python 3.10 on Ubuntu

If you ls, you should have a Python-3.10.14.tgz file. Go ahead and extract it as such:

sudo tar -xvf Python-3.10.14.tgz

A ls should give the extracted Python-3.10.14 directory:

Installing Python 3.10 on Ubuntu

You need to cd to this folder as such:

cd Python-3.10.14

You should have the Python 3.10 source code ready on your Ubuntu LTS.

Installing Python 3.10 on Ubuntu

How to Install the New Python 3.10.14 to Ubuntu

You now have all the files you need to let Ubuntu install Python 3.10. You will need to prepare the make files that Ubuntu will use to install Python 3.10.14. In this case, Ubuntu uses the ./configure --enable-optimizations command

This command will get executed inside the Python-3.10.14 folder as follows:

sudo ./configure --enable-optimizations

Installing Python 3.10 on Ubuntu

Here, the Ubuntu system will generate a Python 3.10.14 makefile. Once the above command is executed, run a ls command and confirm the makefiles are ready as such:

Installing Python 3.10 on Ubuntu

Finally, run the makefile using the make command:

sudo make install

The command will take a few minutes. Be patient. This command will install Python 3.10 on Ubuntu 22.04|20.04. At the same time, you will note that Ubuntu will also Install pip compatible for Python 3.10 on your system:

Installing Python 3.10 on Ubuntu

Check the available Python version and you should expect to get the installed Python 3.10.14:

python3 --version

Installing Python 3.10 on Ubuntu

Installing Python 3.10 on Ubuntu using Apt Repository

Deadsnakes PPA will have these Python versions. It checks first-party repositories to get the Python version you want to install on your machine.

However, this approach has inconsistencies and can’t get Python on any Ubuntu LTS. This way:

⚠️ FROM PPA maintainer You have NO guarantee for security problems. Otherwise, PPA will install your Python version at your own risk.

Also, this approach is deprecated on Ubuntu 18.04.

For these reasons, I decided to only stick with installing Python 3.10 from the Source and let Ubuntu LTS remain secure with no inconsistencies.

An Alternative Case Of Installing Python 3.10 on Ubuntu with Pyenv

You can manage multiple Python versions on the same Ubuntu machine. This way, you don’t have to install and uninstall previous versions.

Pyenv allows you to do so. You install multiple versions and switch the version you want to use at any given time.

In this How to Install Python 3.11 on Ubuntu, I have demonstrated how to use Pyenv and run specific Python versions of choice.

Conclusion

You have now installed Python 3.10 on Ubuntu 22.04|20.04 and learned:

  • How to install Python version 3.10 on Ubuntu from Python source code.
  • Installing Python 3.10 using PPA deadsnakes on Ubuntu.
  • Exploring the alternative to using Pyenv to manage different Python versions.
How to Install|Upgrade Python 3.10 on Ubuntu 22.04|20.04 ✅

Written By:

Joseph Chege