How to Install Python 3.9 on Ubuntu 21.04

Ubuntu has had Python installed by default since at least version 8.04 and since 18.04 LTS the python included in the base system is Python 3.

python command to run commands for any older Python 2.x version, to run a command using the newer version, use python3.

You can check the python version by executing the following command.

python3 --version

If python is not installed by default, you can install it by using the following command.

apt install python3

Output:

root@vps:~# apt install python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpython3-stdlib python3-minimal python3.9 python3.9-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.9-venv python3.9-doc binutils
  binfmt-support
The following NEW packages will be installed:
  libpython3-stdlib python3 python3-minimal python3.9 python3.9-minimal
0 upgraded, 5 newly installed, 0 to remove, and 0 not upgraded.
Need to get 2,387 kB of archives.
After this operation, 6,460 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Next, check the python version.

root@vps:~# python3 -V
Python 3.9.7

How to Install Python 3.9 on Ubuntu 21.04

Ubuntu has had Python installed by default since at least version 8.04 and since 18.04 LTS the python included in the base system is Python 3.

python command to run commands for any older Python 2.x version, to run a command using the newer version, use python3.

You can check the python version by executing the following command.

python3 --version

If python is not installed by default, you can install it by using the following command.

apt install python3

Output:

root@vps:~# apt install python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpython3-stdlib python3-minimal python3.9 python3.9-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.9-venv python3.9-doc binutils
  binfmt-support
The following NEW packages will be installed:
  libpython3-stdlib python3 python3-minimal python3.9 python3.9-minimal
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,387 kB of archives.
After this operation, 6,460 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Next, check the python version.

root@vps:~# python3 -V
Python 3.9.7