How to Install Python 3.9 on Ubuntu 22.04 LTS - LinuxCapable (2023)


Pythonis one of the most popular high-level languages, focusing on high-level and object-oriented applications from simple scrips to complex machine learning algorithms. Python is famous for its simple, easy-to-learn syntax, emphasizes readability, and reduces program maintenance costs and more straightforward conversion to newer releases. Python supports modules and packages, and one of the many is the popular PIP package manager.

Some of the features Python can do:

  • Python can be used on a server to create web applications.
  • Python can be used alongside software to create workflows.
  • Python can connect to database systems. It can also read and modify files.
  • Python can be used to handle big data and perform complex mathematics.
  • Python can be used for rapid prototyping or production-ready software development.

Release Highlights of Python 3.9:

New syntax features:

  • PEP 584, union operators added todict;
  • PEP 585, type hinting generics in standard collections;
  • PEP 614, relaxed grammar restrictions on decorators.

New built-in features:

  • PEP 616, string methods to remove prefixes and suffixes.


New features in the standard library:

  • PEP 593, flexible function and variable annotations;
  • os.pidfd_open()added that allows process management without races and signals.

Interpreter improvements:

  • PEP 573, fast access to module state from methods of C extension types;
  • PEP 617, CPython now uses a new parser based on PEG;
  • several Python builtins (range, tuple, set, frozenset, list, dict) are now sped up usingPEP 590vectorcall;
  • garbage collection does not block resurrected objects;
  • several Python modules (_abc,audioop,_bz2,_codecs,_contextvars,_crypt,_functools,_json,_locale,math,operator,resource,time,_weakref) now use multiphase initialization as defined by PEP 489;
  • several standard library modules (audioop,ast,grp,_hashlib,pwd,_posixsubprocess,random,select,struct,termios,zlib) are now using the stable ABI defined by PEP 384.

New library modules:

  • PEP 615, the IANA Time Zone Database, is now present in the standard library in thezoneinfomodule;
  • an implementation of a topological sort of a graph is directly provided in the newgraphlibmodule.

Release process changes:

  • PEP 602, CPython adopts an annual release cycle.

For the official Python 3.9 rundown notes, visit the official Python webpage What’s New in Python 3.9.

In the following tutorial, you will learn how to download the latest Python 3.9 and install the archive format or use a PPA with this version of Python on Ubuntu 22.04 LTS Jammy Jellyfish using the command terminal, along with how to download and compile as an alternative method.


Table of Contents

(Video) How to Install Django on Ubuntu 22.04 LTS

Update Ubuntu

Before you begin, run a quick update to ensure your system is up-to-date to avoid conflicts during the tutorial and good system maintenance.

sudo apt update && sudo apt upgrade

Install Python 3.9 – PPA Method

The first and easiest solution for Ubuntu users would be to import the “deadsnakes” team Launchpad PPA. This will always contain the latest updates for Python and all extra packages that may be required.

First, install the prerequisite for adding custom PPAs.

sudo apt install software-properties-common -y

Second, add the deadsnakes/ppa to your APT package source list with the following command.

sudo add-apt-repository ppa:deadsnakes/ppa -y

Once the repository has been imported, run an APT update to fresh your package manager to reflect the new imported PPA.

sudo apt update


You can now install Python 3.9 by executing the following code:

sudo apt install python3.9 -y

To verify the installation and Python 3.9 build version, perform the following.

python3.9 --version

Example output:

Optionally, you can install the following extras.

Install development headers for building C extensions:

sudo apt install python3.9-dev -y

Install the standard library (venv) module:

sudo apt install python3.9-venv -y


Install the standard library (distutils) module:

sudo apt install python3.9-distutils -y

Install the (2to3.9) utility as well as the standard library (lib2to3) module:

sudo apt install python3.9-lib2to3 -y

Install the standard library (dbm.gnu) module:

sudo apt install python3.9-gdbm -y

Install the standard library (tkinter) module:

(Video) How to install Anaconda navigator for Jupyter Notebook and Spyder IDE for Python in Ubuntu 22.04 LTS

sudo apt install python3.9-tk -y

Alternative – Nightly Builds

For developers that require the latest nightly builds, the PPA has an additional branch for these builds. However, they should only be used by professionals and developers who need such builds.

Please note that developers or testers should only use this. The stable repository should suit nearly all users and is updated just as often as the nightly version. Also, this PPA can break, meaning you may need to revert to the stable repository.

sudo add-apt-repository ppa:deadsnakes/nightly -y


If you have the default 3.9 stable by (deadsnakes/ppa), you can run the apt update command to upgrade the existing packages.

sudo apt update

Then upgrade the packages:

sudo apt upgrade

If you do not have Python installed, use the installation command, and along with the same commands, add the extra packages such as dev, and venv packages, as shown in the stable branch tutorial rundown.

sudo apt install python3.9 -y

Suppose you want to roll back to the stable PPA. First, remove python 3.9.

sudo apt autoremove python3.9*

Next, remove the Nightly build PPA by adding the –remove to the original command as shown below.

sudo add-apt-repository --remove ppa:deadsnakes/nightly -y

Once done, update the APT repository list to reflect the removal.

sudo apt update


Now re-install Python 3.9; do not forget to re-add the stable repository. By default, you should have kept this.

Install Python 3.9 – Manual Method

Download Python 3.9

First, visit the official download page and grab the latest version or the particular one you are after. The exact instructions should work on any version since you are compiling it. Once you have copied the link, use the wget command to download the Python 3.9 archive.



Extract the Python archive, and remember to change the version number if you downloaded a newer one.

tar -xf Python-3.9.{version}.tar.xz

Optionally, move Python 3.9 to a proper destination like the /opt/ directory.

sudo mv Python3.9.{version} /opt/

Now install the dependencies required to install Python 3.9.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev pkg-config make -y


(Video) How to install PyCharm on Ubuntu 20.04 LTS Linux

Navigate to the directory.

cd /opt/Python3.9.{version}/

Now, run the ./configure –enable-optimizations command.

./configure --enable-optimizations --enable-shared

Note, The script performs several checks to make sure all of the dependencies on your system are present. The ./configure –enable-optimizations will optimize the Python binary by running multiple tests, which will make the build process slower.

Now that you have built and configured the environment, it is time to compile it with the commandmake.


A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server.

For example, the LinuxCapable machine has 6 CPUs, and I can use all six or at least use 4 to 5 to increase speed.

make -j 6


Once you have finished building, install Python binaries as follows:

sudo make altinstall

Note, it is advised to use the make altinstall command NOT to overwrite the default Python 3 binary system.

Next, after the installation, you need to configure the dynamic linker run-time bindings with the ldconfig command.

sudo ldconfig /opt/Python3.9.{version}

Note, do not skip this, or you will face issues. You will also need to replace the path with your directory name and version.

Confirm that Python 3.9 is installed and the build version by running the following command.

python3.9 --version

Example output:

Create a Virtual Environment


Python’s venv module is a virtual environment is a Python environment such that the Python interpreter, libraries, and scripts installed into it are isolated from those established in other virtual environments, and (by default) any libraries installed on your operating system, for example, those that are installed on your Ubuntu system to avoid clashing and disturbing your production environments.

To ensure Python 3.9 is installed correctly and functioning, create a quick Python project.

First, create the project directory and navigate to it:

(Video) How to install Python 3.9 and PIP on Ubuntu 20.04

mkdir ~/test_app && cd ~/test_app

Inside the project root directory, run the following command to create a virtual environment for the test name test_app.

python3.9 -m venv test_app_venv

Note, users that installed the PPA, you will need to install the Python 3.9 venv package if it has not already been installed.

sudo apt install python3.9-venv -y

Next, activate the virtual environment as follows.

source test_app_venv/bin/activate


After starting the virtual environment, you will now be in the shell prompt terminal. This will show the name of your environment that will be prefixed.


To exit the virtual environment, use the following command:


Install Python PIP with 3.9

By default, installing python-3.9 using the following APT command should work for all those using the Python PPA repository.

sudo apt install python3-pip

The manual installation method should have attached PIP; if not, it is advised to install PIP by downloading using the wget command.


Next, install the file downloaded.



Once installed, it is a good idea to check for upgrades.

python3.9 -m pip install --upgrade pip

Example output:

Now verify the PIP 3.9 version installed with the following command.

pip3.9 --version

Example output:

(Video) 22 Things You MUST DO After Installing Ubuntu 22.04 LTS (JAMMY JELLY FISH)

Comments and Conclusion

In the tutorial, you have learned how to install Python 3.9 and create a virtual test environment on Ubuntu 22.04 LTS Jammy Jellyfish desktop or server.

Currently, Python 3.9 is considered an older stable LTS release at the moment of the tutorial. Most should consider moving to Python 3.10 with the newer 3.11 around the corner.


What version of python does Ubuntu 22.04 use? ›

Ubuntu 22.04 comes with Python 3.10. 4, which is the most current version as of right now and, impressively, was only released a month ago.

What version of python does Ubuntu 20.04 use? ›

In 20.04 LTS, the python included in the base system is Python 3.8.

How do I upgrade python 3.8 to python 3.9 in Ubuntu? ›

How to upgrade to Python 3.9. 0 on Ubuntu 18.04 LTS
  1. Step 1: Add the repository and update.
  2. Step 2: Install the Python 3.9.0 package using apt-get.
  3. Step 3: Add Python 3.6 & Python 3.9 to update-alternatives.
  4. Step 4: Update Python 3 for point to Python 3.9.
  5. Step 5: Test the version of python.
7 Dec 2020

Is Ubuntu 22.04 a LTS? ›

Ubuntu is the target platform for open source software vendors and community projects. Ubuntu 22.04 LTS ships with the latest toolchains for Python, Rust, Ruby, Go, PHP and Perl, and users get first access to the latest updates for key libraries and packages.

Is Ubuntu 22.04 LTS stable? ›

According to this, Ubuntu 22.04 is an LTS release, which means that it has long-term support. This article claims that LTS releases are stable, and users should install them. The Ubuntu website also states that Version 22.04 is an LTS release.

How do I download Python 3.9 on Linux? ›

Perform the below-given steps to install Python 3.9 on Linux Mint 20 from the deadsnakes repository:
  1. Step 1: Update apt cache. ...
  2. Step 2: Install the dependencies. ...
  3. Step 3: Add PPA repository. ...
  4. Step 4: Install Python 3.9. ...
  5. Step 5: Verify the Python 3.9 installation.

How do I choose Python version in Ubuntu? ›

Switch Python Version on Ubuntu & Debian
  1. Create a symlink from /usr/bin/python2. ...
  2. Change the symlink link to /usr/bin/python3. ...
  3. Repeat step 2 to add more Python version to group, which is already installed on your system.
  4. At this point, You have added two python binary versions to the group name “python”. ...
  5. That's it.
5 Oct 2021

How do I install the latest Python version in Ubuntu? ›

Here's how to do it:
  1. Open up your terminal by pressing Ctrl + Alt + T.
  2. Update your local system's repository list by entering the following command: sudo apt update.
  3. Download the latest version of Python: sudo apt install python3.
  4. APT will automatically find the package and install it on your computer.
21 Apr 2022

How long will Ubuntu 20.04 LTS be supported? ›

Ubuntu 20.04 LTS

LTS stands for long-term support — which means five years, until April 2025, of free security and maintenance updates, guaranteed. Request our latest build of Ubuntu Linux for your SCSCF supported Linux computer today! See Canonical's Release Cycle Page:

How do I update Ubuntu 20.04 to LTS? ›

Share This Article
  1. Prerequisites.
  2. Step 1: Backup all your data.
  3. Step 2: Upgrade all the system packages.
  4. Step 3: Open TCP port 1022.
  5. Step 4: Upgrade to Ubuntu 22.04 Jammy Jellyfish.
  6. Step 5: Verify the upgrade to Ubuntu 22.04.
  7. Step 6: Delete the firewall rule you created.
  8. Step 7: Enable third-party repositories.
3 Jun 2022

How do I install Python 3.8 on Ubuntu? ›

Installing Python 3 on Linux
  1. $ python3 --version. ...
  2. $ sudo apt-get update $ sudo apt-get install python3.6. ...
  3. $ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt-get update $ sudo apt-get install python3.8. ...
  4. $ sudo dnf install python3.

How do I update Python 3.8 Linux? ›

Install Python 3.8
  1. Step 1: Add the repository and update. Latest Python 3.8 not available in Ubuntu's default repositories. ...
  2. Step 2: Install the Python 3.8 package using apt-get. ...
  3. Step 3: Add Python 3.6 & Python 3.8 to update-alternatives. ...
  4. Step 4: Update Python 3 for point to Python 3.8. ...
  5. Step 5: Test the version of python.
29 Jan 2020

Do I need to install pip? ›

PIP for Python is a utility to manage PyPI package installations from the command line. If you are using an older version of Python on Windows, you may need to install PIP.

How can I make Ubuntu 22.04 faster? ›

If you've upgraded to Ubuntu 22.04 then you probably noticed how smooth the GNOME experience is.
Why Ubuntu 22.04 is so fast (and how to make it faster)
  1. Wait for the monitor to display the last frame.
  2. Wait a little bit more.
  3. Prepare the next frame behind the scenes.
  4. Offer the next frame to the monitor.
  5. Goto 1.
2 Sept 2022

What is the latest LTS version of Ubuntu? ›

The last LTS release was in 2022, Ubuntu 22.04. The other release in 2022, Ubuntu 20.10, is called an interim release.

Is Ubuntu 20.04 LTS stable? ›

Yes, Ubuntu 20.04 LTS is stable. Because it gets security updates but doesn't get feature update for more than one year now, and will continue the same way for the next 4 years or 9 years if you subscribe to Ubuntu Advantage. , which is basically the same kernel as that the current release of non - LTS Ubuntu has.

What version of Python do I have Ubuntu terminal? ›

You can use python -V (et al.) to show you the version of Python that the python command resolves to. If that's all you need, you're done. But to see every version of python in your system takes a bit more. In Ubuntu we can check the resolution with readlink -f $(which python) .

How do I install Python 3.10 on Ubuntu? ›

Install Python 3.10
  1. Step 1: Add the repository and update. ...
  2. Step 2: Install the Python 3.10 package using apt-get. ...
  3. Step 3: Add Python 3.8 & Python 3.10 to update-alternatives. ...
  4. Step 4: Update Python 3 for point to Python 3.10. ...
  5. Step 5: Test the version of python.
23 Dec 2021

How do I install Python 3.8 13 on Ubuntu? ›

Steps to install Python 3.9 or 3.8 on Ubuntu 22.04 LTS
  1. Start with the system update. ...
  2. Add PPA for Python old versions. ...
  3. Check Python Versions you want. ...
  4. Install Python 3.9 on Ubuntu 22.04. ...
  5. Install Python 3.8 on Ubuntu. ...
  6. Set the default Python version. ...
  7. Uninstall Python and PPA.
30 Jun 2022

How do I make Python 3.6 default Ubuntu? ›

Steps to Set Python3 as Default On ubuntu?
  1. Check python version on terminal - python --version.
  2. Get root user privileges. On terminal type - sudo su.
  3. Write down the root user password.
  4. Execute this command to switch to python 3.6. ...
  5. Check python version - python --version.
  6. All Done!
8 Nov 2020


1. How to Install Python3 on Ubuntu 21.04 Linux | sudo apt Install Python3 | Python pip Install | pip3
2. How to install python3 turtle on linux |#linux |#ubuntu |#turtle |#python|#sendex|#mrbeast|#mkbhd
(Kalyan EDU_IN)
3. How to Install Python 3.7 on Ubuntu 18.04 LTS?
4. Python Environment Setup - Ubuntu - Downgrading to Python 3.7.7
(Galvanize Data Science)
5. Install | Python 3.9 | Pycharm | Ubuntu 20.04
(Jogi John)
6. Nvidia Cuda, cuDNN, Conda, PyTorch and TensorFlow Installation with Ubuntu 22.04
Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated: 29/07/2023

Views: 5640

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.