How To Install Python On Linux

How To Install Python On Linux

Python is one of the most popular programming languages right now in the world. Almost every operating system supports Python. In this tutorial, we are going to show you a step-by-step guide to installing Python on Linux-based operating systems.

How To Install Python On Linux

Step 1:

Install build-essential packages required to build Python.

For Ubuntu And Debian-Based Operating Systems:

sudo apt update
sudo apt install build-essential zlib1g-dev \
libncurses5-dev libgdbm-dev libnss3-dev \
libssl-dev libreadline-dev libffi-dev curl

For Fedora-based operating systems:

sudo dnf groupinstall development

Step 2:

Download the  latest version of Python 3

Download the latest version of Python 3 from the official website of Python. After the download is complete, you will have a .tar.xz archive file (a “tarball”).

Step 3:

Now, Extract the tarball file that you have downloaded in the above command.

tar -xf Python-3.x.x.tar.xz

Step 4:

Navigate to the configure file and execute it in your Linux terminal with:

cd Python-3.*

Step 5:

To install new Python alongside the version of Python installed on your system:

sudo make altinstall

The build process may take some time.

To replace the current version of Python with this new version, you should uninstall your current Python package using your package manager and then install:

sudo make install

Step 6:

To verify it, run the following commands in your terminal:

python3 --version


python --version

If the output says Python 3.x, Python 3 has been successfully installed in your Linux.


Create a Python virtual environment in Linux

Run the following command to create a virtual environment:

python3.8 -m venv foldername

To activate the virtual environment, run the following command:

$ source example/bin/activate
(foldername) $

Notice that your terminal prompt ($) is now preceded by an environment name.

To deactivate the virtual environment, simply run the deactivate command:

(foldername) $ deactivate

Leave a Comment