This tutorial will be helpful for beginners too, on how to install Python on Linux and also shows how to compile and install Python 3.11 on Linux distributions (ie) Ubuntu, Linux Mint, AlmaLinux, Fedora, and Rocky Linux.
What is Python?
Python is a programming language with many features, such as an intuitive syntax, powerful data structures, and robust support for object-oriented programming.
Python is used in a variety of domains, such as web development, scientific computing, and artificial intelligence.
Install Python 3.11 on Ubuntu / Linux Mint
Python can be installed on Linux systems via 2 methods
- Method 1: Via Repository
- Method 2: Via Source file
Method 1: Via Repository
For Debian-based systems
Step 1: Add the DeadSnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa
Step 2: Update the repository and install Python 3.11
sudo apt install python3.11
Step 3: To verify the installation, open a terminal window and type the following command:
From the above image Python, 3.8 is the default one, If you want to use Python 3.11 as your default Python, then you can type the following commands
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
Step 4: Configure Python 3.11 as the default
sudo update-alternatives --config python3
Method 2: Via Source file
Step 1: Install the required dependencies before proceeding
sudo apt install build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
Step 2: Download the Python Source file from the FTP site or use the below command
Step 3: Extract the contents
tar -xf Python-3.11.0.tar.xz && cd Python-3.11.0 && mv Python-3.11.0/ /opt/
Step 4: Configure Python from the source file
sudo ./configure --prefix=/opt/Python-3.11.0 --enable-optimizations
Step 5: Build and install Python 3.11
sudo make altinstall -j4
From the above command, I have provided j4, you can provide the numbers based on your CPU.
Step 6: Set Python 3.11 as the default
sudo update-alternatives --install /usr/bin/python python /opt/Python-3.11.0/python 1
Uninstall Python 3.11
To uninstall Python 3.11 run the below command
sudo apt remove python3.11
From this tutorial, you have learned how to download and install Python 3.11 on Ubuntu 22.04, 20.04, and Linux Mint 21
Do let us know your comments and feedback in the comments section below.
If my articles on TipsonUNIX have helped you, kindly consider buying me a coffee as a token of appreciation.
Thank You for your support!!
1 thought on “How to Install Python 3.11 on Ubuntu / Linux Mint”
You should NOT set Python 3.11 as default if possible. Some Linux packages (the most notable being X-server) depend on your default Python installation. If you change the default version, they may stop working correctly (it may only be noticeable after rebooting). Instead, if you want to use Python 3.11, just type “python3.11” in your terminal