• Chandrakumar Murugesan

Python 3.11: How to install on Ubuntu?


It's a simple process to install the new Python 3.11 on Ubuntu. After careful investigation, I found deadsnakes PPA is the right choice to install the latest versions of Python.


This tutorial is created after running the steps on the system Ubuntu 20.04 on Azure Virtual Machine.


Prerequisite Steps

We can follow this setup as a standard setup step for all the python versions. These steps can be ignored if the deadsnakes PPA is already configured on your system.

Update the Ubuntu to make sure the system is up to date

$ sudo apt update
$ sudo apt upgrade
Now configure the deadsnakes's PPA This part of the Prerequisite Step is not required for Ubuntu version 22.04 or higher. As the 3.11 is available in the default Ubuntu Repository.

Install software-properties-common. Most of the Ubuntu systems preinstall with this package.
$ sudo apt install software-properties-common apt-transport-https -y

Add deadsnakes's PPA

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

Install Python 3.11

$ sudo apt install python3.11 -y

Now Python 3.11 and ready to go. Run the following command to make sure it's working fine.

$ python3.11 --version
Python 3.11.0 // the output will be

Optional Steps

Make Python version 3.11 the default python version.

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2

And to make sure and select the correct version of the Python

$ sudo update-alternatives --config python3 
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
 Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.11   2         auto mode
* 1            /usr/bin/python3.11   2         manual mode
  2            /usr/bin/python3.8    2         manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
$ python3 --version
Python 3.11.0 // the output will be

We can also map the python command to python3. python-is-python3 package help to do this.

$ sudo apt install python-is-python3 -y
$ ptyhon --version
Python 3.11.0 // the output will be

Bonus Steps

Most of us love to use venv to create python's virtual environment for all our projects.

$ sudo apt install python3.11-venv -y
...

To try. Based on your default Python setup, choose the correct command from the following.

$ python3.11 -m venv .venv
or
$ python3 -m venv .venv
or
$ python -m venv .venv 

I am so excited to try the new features of Python 3.11. Please read the release note before trying it.

14 views0 comments

Recent Posts

See All