How to Install Python 3.9 on Ubuntu 20.10 and Ubuntu 20.04

Python 3.9.0 released. How to install Python in Linux Ubuntu via command line. Here are the terminal commands to install Python 3.9 on Ubuntu 2010 and Ubuntu 20.04

Python 3.9.0 is the stable release of Python programming language, and it contains many new features and optimizations.

Python 3.9.0 new features

Some of the new major new features and changes in Python 3.9 are:

  • PEP 573, Module State Access from C Extension Methods
  • PEP 584, Union Operators in dict
  • PEP 585, Type Hinting Generics In Standard Collections
  • PEP 593, Flexible function and variable annotations
  • PEP 602, Python adopts a stable annual release cadence
  • PEP 614, Relaxing Grammar Restrictions On Decorators
  • PEP 615, Support for the IANA Time Zone Database in the Standard Library
  • PEP 616, String methods to remove prefixes and suffixes
  • PEP 617, New PEG parser for CPython
  • BPO 38379, garbage collection does not block on resurrected objects;
  • BPO 38692, os.pidfd_open added that allows process management without races and signals;
  • BPO 39926, Unicode support updated to version 13.0.0;
  • BPO 1635741, when Python is initialized multiple times in the same process, it does not leak memory anymore;
  • A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall;
  • A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489;
  • A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384.

Install Python 3.9.0 in Ubuntu

Run the following commands in terminal to install Python 3.9.0 in Ubuntu:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
python --version

Install Python 3.9.0 in Ubuntu from Source

Run the following set of command to install Python 3.9 on Ubuntu from source. Users can compile Python from the source through the apt package manager.


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
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar -xf Python-3.9.0.tgz
cd Python-3.9.0
./configure --enable-optimizations
make -j 12
sudo make altinstall

The next release after 3.9 will be 3.10. It will be an incremental improvement over 3.9, just as 3.9 was over 3.8, and so on.

Original Article