Python 3.11 releases with excellent promises. The best of all is its speed. It's up to 60% faster than Python 3.10.
Here's how to install it on Ubuntu 22.04 LTS (jammy). It also works on Ubuntu 18.04 (bionic) and Ubuntu 20.04 (focal)
The installation involves three steps:
- adding the deadsnakes PPA to your list of repositories;
- instaling Python 3.11;
- switch your default Python version in the system.
Additionally, this tutorial will also help you install related Python packages. We'll install a virtual environment and the dev packages.
Add the deadsnakes PPA to the Ubuntu repositories list.
The easiest way to manage repositories in Ubuntu is using the add-apt-repository. Ubuntu 20.04 comes with this utility installed. But if you're on a previous version or get the "add-apt-repository command not found" error, you may want to install it manually. The following command will install the utility.
$ sudo apt install software-properties-common
Once you have the utility installed, you can use the following shell command to add the deadsnakes repository.
$ sudo add-apt-repository ppa:deadsnakes/ppa
You will be prompted to confirm the action. Press enter to continue.
Adding a repository will usually trigger an update. If it doesn't, you can run it manually.
$ sudo apt update
Installing Python 3.11
If you've added the repository, it's relatively easy to install Python 3. 11. You can use apt to install it as follows.
sudo apt install python3.11
You may be prompted to accept the installation. Once the installation is complete, type
python3.11 in the terminal window. If you can access the Python shell, your installation is successful. Also, you can see the version of Python is 3.11.
Making Python 3.11 the default version.
Congratulations on installing Python 3.11. But have you noticed that the default Python version is still your old one?
You can change it with the following command.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
Now test the python version, and you'll see it's 3.11.
$ python --version Python 3.11.0rc2
Installing supporting packages for Python 3.11.
Python projects often need a bunch of other packages to work correctly. These supporting packages include python-dev, virtualenv, distutils. You must install them with your new upgrade of Python. The following command will install them.
$ sudo apt install python3.11-dev python3.11-venv python3.11-distutils python3.11-gdbm python3.11-tk python3.11-lib2to3
Here's an explanation of what they are and why you need them as explained in deadsnakes PPA description.
`python3.11-dev`: includes development headers for building C extensions.
`python3.11-venv`: provides the standard library `venv` module.
`python3.11-distutils`: provides the standard library `distutils` module.
`python3.11-lib2to3`: provides the `2to3-3.11` utility and the standard library `lib2to3` module.
`python3.11-gdbm`: provides the standard library `dbm.gnu` module.
`python3.11-tk`: provides the standard library `tkinter` module.