Python 3.11 is the latest stable version at the time of writing of tutorial. Which comes with multiple new features and security upgrades. This version comes with improved error messages for common mistakes in type hints. A new syntax for variable annotations, to make it more clear when a variable is intended to be used for type hints versus other purposes. Improved the support for type checking and type inference in the standard library and third-party libraries.
In this tutorial, we will help you to install Python 3.11 on Ubuntu, Debian, and Linux Mint operating systems using PPA as well as compiling it from the source code. This tutorial will also work on other Debian-based Linux systems.
The compilation of source code required multiple build libraries on the system. Which can be installed by running the following command before proceeding with the next steps.
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Method 1: Installing Python 3.11 using PPA
The ~deadsnakes team is maintaining a PPA that contains the Python Debian packages. You can configure this PPA in your system and install Python versions.
To add the PPA to your system, execute:
sudo add-apt-repository ppa:deadsnakes/ppa
Then you can install Python 3.11 using apt-get package manager.
sudo apt install python3.11
This will install Python 3.11 on your Linux system.
Method 2: Installing Python 3.11 using Source Code
If the repository doesn’t contain the Python packages for your system, install it by compiling it from the source code.
- Download Python 3.11 source code: Python 3.11.1 version is available for installation. You can visit the Python official websites to check for the latest available version. Use the following commands to download the Python 3.11 source code.
- Extract archive:Once the download is finished, extract the archive file content.
sudo tar xzf Python-3.11.1.tgz
- Prepare source code: Now prepare the source code as per your system architecture and environment. Also use
--enable-optimizationsoption with configure command to enable additional supports like SSL, bz2 support.
sudo ./configure --enable-optimizations
- Compile and install: After preapring the source code, compile it using make command. With make use
altinstall, to install it as a separate Python. So that this will not overwrite the existing Python installation.
sudo make altinstall
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
sudo wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
Step 3: Check Python Version
Finally, you have successfully installed Python 3.11 on your system. Let’s check the version installed of python using the below command.
python3.11 -VPython 3.11.1
Step 4: Installing PIP
This will also configure PIP for you to install Python modules.
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
Once the PIP is installed successfully, check its version by executing command:
pip3.6 -Vpip 22.3.1 from /usr/local/lib/python3.11/dist-packages/pip (python 3.11)
In conclusion, installing Python 3.11 on Ubuntu, Debian, and Linux Mint by compiling the source code is a straightforward process. It involves downloading the source code, extracting it, configuring it, building it, and finally installing it. By following the steps outlined in this guide, you should be able to successfully install Python 3.11 on your system and start using it for your programming needs. Keep in mind that compiling the source code can take a while, and you may need to have the necessary dependencies and tools installed on your system. However, this method offers the most flexibility and control over the installation process.