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 dead snakes PPA to your list of repositories;
- installing 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.
Speaking of upgrading Python, do checkout the book Expert Python Programming: Master Python by learning the best coding practices and advanced programming concepts. This is a Python programming book for experts who want to advance their skills with the latest Python features.
Add the dead snakes 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.
Once you have the utility installed, you can use the following shell command to add the dead snakes repository.
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.
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.
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.
Now test the Python version, and you’ll see it’s 3.11.
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.
Here’s an explanation of what they are and why you need them, as explained in Deadsnake’s 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.
Not a Medium member yet? Please use this link to become a member because I earn a commission for referring at no extra cost for you.