In this tutorial, you will learn how to install Python on Debian 11 Bullseye. One option is to install from the Debian repository with apt command, or we can manually install the latest official release of Python from Python.org. We’ll cover both methods below.
Install From Debian Repo
This is the easiest method, but you won’t always get the absolute latest Python release:
$ sudo apt update $ sudo apt install python
Install Latest Version From Official Download
The next method takes a few additional steps, but ensures that you download and install the absolute latest Python release.
Step 1. Before installing Python, always make sure that you have your system up to date:
$ sudo apt update $ sudo apt upgrade
Step 2. Next, we’ll install the dependencies:
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev
Step 3. Navigate to the Python download page and choose from either the latest stable release or pre-release version. Download either the compressed gzipped tarball, or the xz tarball.
Step 4. Extract the downloaded file with tar command:
$ cd ~/Downloads $ tar -xf Python-*
Step 5. Change into the directory where the Python source was extracted:
$ cd Python*/
Step 6. Optimize the Python build process by executing:
$ ./configure --enable-optimizations
Step 7. Once done, we build the Python source with the
make command followed by the
-j parameter and the number of cores that you have in your system. You can check this by running the
$ make -j 2
Step 8. Finally, proceed to install Python:
$ sudo make altinstall
altinstall option is necessary to ensure that the system-default Python files won’t be touched.
Step 9. To verify that the installation was successful, execute the following command and you should see the expected version number:
$ python3.11 --version
3.11 with the version number that you installed.