Ubuntu

How to Install Python on Ubuntu 22.04?

How to Install Python on Ubuntu 22.04

Python is a very popular High-Level programming language that focuses on improving code reliability, developer productivity, and runtime performance. It is commonly used for Website Development, Data Analysis, and Data Visualization. Python’s significant features make it a preferred choice among Ubuntu users for scripts and tool development.

This article focuses on the installation procedure of Python on the latest Ubuntu 22.04 version.

How to Install Python on Ubuntu 22.04?

Python can be installed by Two Methods:

  1. Using the PPA Repository.
  2. Using Official Setup File.

Method 1: Installing Python on Ubuntu 22.04 Using the PPA Repository

The PPA (Personal Package Archive) repository hosts software packages that are built and developed by individuals as open-source. The steps below explain the installation procedure of Python using the PPA Repository.

Step 1: Updating System Packages

Before installing Python, ensure that the system packages are up to date using the command below:

sudo apt update

Now use the command to upgrade these packages:

sudo apt upgrade

Step 2: PPA Repository

Add the PPA Repository before installing Python. For this purpose, execute the below-stated “sudo” command:

sudo add-apt-repository ppa:deadsnakes/ppa

It will ask for the confirmation of adding the repository, Press “Enter” to proceed further:

Once the Repository is added, it will inform you by saying the package lists are read:

Step 3: Installing Python

Install Python using the command below:

sudo apt install python3.9

“3.9” is the Python version. You can install any version according to your needs.

Step 4: Validate Python

Execute the command below to validate the Python installation and its version:

python3.9 --version

This is how you can install Python using the PPA Repository.

Method 2: Installing Python on Ubuntu 22.04 Using the Official Setup File

Python can also be installed in Ubuntu 22.04 using the Official Setup file of Python. Follow the steps listed below to install Python using Official Setup.

Step 1: Installing Dependencies

Before installing Python using the setup file, add the following additional dependencies one by one for Ubuntu to install it:

sudo apt install build-essential

Install the “zlib1g-dev” and “libncurses5-dev” now:

sudo apt install zlib1g-dev libncurses5-dev

Now install the “libsqlite3-dev”, “libnss3-dev”, and “libffi-dev” libraries:

sudo apt install libsqlite3-dev libnss3-dev libffi-dev

Once downloaded, install the “libgdbm-dev”, “libreadline-dev”, and “libssl-dev”, and using wget install the “libbz2-dev” libraries.

sudo apt install libgdbm-dev libreadline-dev libssl-dev wget libbz2-dev

Step 2: Download Setup File

Now, using “wget” download the Python Setup File using the command:

wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz

The Python Setup File will be downloaded and saved:

Step 3: Extract the Setup File

Once the setup file is downloaded, extract it now using the command:

tar -xvf Python-3.9.7.tgz

Step 4: Navigate to the Folder

Navigate to the folder where Python is extracted using the “cd” command:

cd Python-3.9.7/

Step 5: Run Script

When you’re inside the Python folder, run the “./configure” script:

./configure --enable-optimizations

Step 6: Process Compile Configurations

Run the command to process the build compile configuration inside the folder:

make

It will take some time, wait for it to be completed:

Step 7: Installing Binaries

To install Python Binaries, use the command:

sudo make altinstall

It will install binaries like Pip:

Step 8: Validating Python

Use the command below to validate the Python Version:

python3.9 --version

This is the process of utilizing the Official Setup File for downloading and installing Python in Ubuntu 22.04.

How to Uninstall Python on Ubuntu 22.04?

If Python is no longer needed, you can uninstall it to free up some disk space. For this purpose, execute the given command:

sudo apt remove python3.9

This will remove all the packages installed in Python on Ubuntu:

That’s all about installing and uninstalling Python on Ubuntu 22.04.

Conclusion

In Ubuntu 22.04, Python can be installed either by using the PPA repository or using Python’s official setup file. Users can verify the existence of Python on their Ubuntu operating system by executing the “python 3.9 –version” command. To uninstall Python from Ubuntu 22.04, use the “sudo apt remove python 3.9” command. This article showcased the process for installing Python on Ubuntu 22.04 using two methods; Using the PPA Repository, and Installing Python using the Official Setup File.

Similar Posts