Python is a programming language that is used to implement various kinds of applications. Python is often used for machine learning, deep learning, computer vision, and data analysis.
This tutorial demonstrates how to install Python 3.12 on Ubuntu 22.04.
Install Python
Add the Python repository:
sudo add-apt-repository -y ppa:deadsnakes/ppa
Install Python 3.12:
sudo apt install -y python3.12
Verify that the installation completed successfully by checking Python version:
python3.12 --version
Testing Python
Create a main.py
file:
nano main.py
Add the following code:
print('Hello world')
Now test a program by running the python3.12
command:
python3.12 main.py
Uninstall Python
If you wish to completely remove Python 3.12, use the following command:
sudo apt purge --autoremove -y python3.12
During installation, additional packages were installed. You can remove them using the following command:
sudo apt purge --autoremove -y mime-support bzip2
Remove GPG key and repository:
sudo rm -rf /etc/apt/trusted.gpg.d/deadsnakes-ubuntu-ppa.gpg*
sudo rm -rf /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-jammy.list
Install older versions
Python 3.10 is installed on Ubuntu 22.04 by default. Deadsnakes repository provides older Python versions as well. The following commands can be used to install Python 3.8, 3.9 or 3.11:
sudo apt install -y python3.8
sudo apt install -y python3.9
sudo apt install -y python3.11
Leave a Comment
Cancel reply