Python, a versatile and widely used programming language, is essential for a variety of applications, from web development to data science. With the release of Python 3.12, many developers are eager to upgrade or install it on their systems. This article provides a detailed, step-by-step guide to installing Python 3.12 on Ubuntu 22.04 and 20.04.
Before you begin, ensure you have:
It’s always a good practice to start by updating your package to ensure you’re installing the latest versions of software packages. Open a terminal and run the following command:
class="terminal">sudo apt update
sudo apt upgrade
Enter your password when prompted.
Python 3.12 requires some essential build tools and libraries. You can install them by running the following command:
sudo apt install -y software-properties-common build-essential libffi-dev libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev libssl-dev
This command will install the necessary dependencies for Python compilation and other libraries required for Python to function properly.
Python 3.12 is not available in the default Ubuntu repositories. To get the latest Python versions, you can use the “DeadSnakes” Personal Package Archive (PPA). Add the PPA to your system by running the following command:
sudo add-apt-repository ppa:deadsnakes/ppa
You will be prompted to press Enter to continue. Do so to add the PPA to your system.
After adding the PPA, update the package list once more to include the new repository:
sudo apt update
Now that you have added the DeadSnakes PPA and updated your package list, you can install Python 3.12 using the following command:
sudo apt install -y python3.12 python3.12-venv
This command will install Python 3.12 and all its related packages.
Check the installed Python version:
python3.12 --version
You should see the Python version displayed in the terminal, confirming that Python 3.12 is installed on your system.
If you want to make Python 3.12 your default Python version, you can use the update-alternatives command. However, be cautious when changing the default Python version, as it may affect system scripts and applications. To set Python 3.12 as the default, run the following commands:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 312
sudo update-alternatives --config python3
Select the number corresponding to Python 3.12 from the list, and press Enter.
Once changes done, you can verify the change with python --version
.
Pip is a package manager for Python. Install it by running:
sudo apt install python3.12-distutils
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.12 get-pip.py
Check the Pip version with pip3 --version
.
After the installation, you may clean up unnecessary packages:
sudo apt autoremove
You’ve successfully installed Python 3.12 on your Ubuntu 22.04 or 20.04 system. This setup opens a pathway to explore the latest features and improvements of Python 3.12. Whether for development, data analysis, or scripting, you’re now ready to take advantage of Python’s powerful capabilities on your Ubuntu machine.
Remember to stay updated with Python and Ubuntu releases for a smooth programming experience.
The post How to Install Python 3.12 on Ubuntu 22.04 / 20.04 appeared first on TecAdmin.
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…
Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…