How to Install Python in Linux

Learn how to install Python on Linux devices with this detailed guide.

Python is an incredibly versatile and powerful programming language that can be used to build powerful applications. Installing Python in Linux can be intimidating for a tech newbie, but don’t worry, this guide will explain how to install Python 3 on Linux devices.
How to Install Python Linux

How to Install Python in Linux

It’s important to note that Python is pre-installed in many Linux distributions, so you may not need to install Python. However, if for any reason the program is missing on your device, you will have to install it. So, let’s get started with how to install Python in a Linux system.

Quick Answer

To install Python on a Linux device:

1. Download the latest edition of Python from the official website.

2. Unpack the .tar.xz file, and run configure script from the Linux terminal.

What Version of Linux Is Compatible with Python?

Python is compatible with all versions of Linux. To install Python on Linux, you can use either the source code or a package manager such as apt, yum, or DNF. You can also use a Python version manager such as pyenv or Anaconda.

Is It Possible to Install Multiple Versions of Python on Linux?

Yes, it is possible to install multiple versions of Python on Linux. Many Linux distributions come with Python pre-installed. 

Can I Install Python Packages From the Command Line in Linux?

Yes, you can install Python packages from the command line in Linux. To install Python on Linux Centos, you need to use the Python package manager, Pip. Pip is a command line program that allows you to install and manage Python packages. To install a package, simply type pip install <package_name>.

What Are the Best Practices for Managing Python Installations on Linux?

  • Use a Python Version Manager: Using a Python version manager such as pyenv or Anaconda will help you manage multiple Python versions installed on your system and make sure you are always running the correct version.
  • Create Virtual Environments: Create virtual environments for each project and install the necessary packages within them. This will help keep your system clean and organized and prevent conflicts between multiple packages.
  • Use Package Managers: Use package managers like pip or conda to install packages. This will ensure that all dependencies are properly installed and that the packages are up-to-date.
  • Upgrade Python Regularly: Make sure to upgrade Python regularly to keep it up-to-date. This will ensure that all the latest features and bug fixes are available.
  • Use Version Control: Use version control to manage changes to your code. This will help keep track of changes, ensuring that you can easily roll back any changes that don’t work out.

Also Read: How to Install Python in Ubuntu

Prerequisite to Install Python 3 on Linux

In order to successfully install Python 3 Linux, there are certain requirements that must be met.

  • Your computer should be running on Debian/Fedora OS.
  • 2GB of RAM and 5GB of disk space.
  • Sudo access to the system you wish to install the software on.

The sudo command enables you to temporarily acquire root privileges on your current user account.

How to Check the Python Version on Linux?

Before you install Python Linux, learn this, Python is generally included in most Linux distributions, like Debian.

So you can check which version is already installed on your system by typing python -V or python –version in the terminal.

If Python is not installed, the output will be different than if it is already installed.

type python -V or python --version in the terminal

when Python is already installed, the output will be different. For example, Python 3.8.5-

Also Read: Fix Command Failed With Error Code 1 Python Egg Info

How to Install Python 3 in Linux

1. Obtain the necessary development packages needed to construct Python.

On Debian:

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

On Fedora:

$ sudo dnf groupinstall development

2. Go to the official Python website, and get the newest edition of Python.

Go to the official Python website, and get the newest edition of Python | install python Linux

3. Once the download is finished, you’ll have a .tar.xz file that contains the source code for Python.

4. Retrieve the contents of the tarball. Once the download is finished, you can either use an extraction program of your preference or use the Linux tar command to unpack the tarball, for example:

$ tar -xf Python-3.?.?.tar.xz

4. Go to the configure script after you have unpacked the Python tarball, and run it from your Linux terminal using:

$ cd Python-3.*

It might take a while for the setup to complete. Don’t move on until it is done.

5: If you already have a different version of Python installed on your computer and would like to install a newer version alongside it, use this command.

$ sudo make altinstall

It may take a while to complete the construction. If you wish to switch from your current version of Python to the new version, you should first uninstall the existing Python package using your package manager (like apt or DNF) and then install it again.

$ sudo make install

Note: It is usually better to install programs through a package like a .deb or .rpm file, so the system can manage the updates for you. Since this article is discussing the installation of the latest Python version which is not yet packaged, it means that you do not have that option. You can either use Altinstall to install Python, or you can customize an existing Python package by using the latest source code. This is an advanced topic that is specific to your particular distribution and is outside the scope of this article.

6. If there have been no issues, the most current version of Python should now be set up on your Linux device. To confirm this, enter one of the following commands into your terminal:

python3 --version


python --version

If the result of the command displays Python 3.x, that means Python 3 has been successfully installed.

Also Read: Top 14 Best Graphics Card for Linux

How To Uninstall Python From Linux

Deleting the pre-installed version of Python can cause the OS to stop functioning correctly. The Graphical Display Manager is particularly prone to failing when Python is uninstalled. Thus, it is only possible to uninstall Python versions that you have installed manually.

1. To delete the Python version you have added, enter the following command on the Terminal:

sudo apt purge -y python2.x-minimal

2. You can take Python 3 off Linux versions with this command:

sudo ln -s /usr/bin/python3 /usr/bin/python

3. To get rid of pip from the structure, use these commands:

sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip

If the instructions do not work, it is probable that you need to refresh your repository listing using sudo apt-get update.

We hope this guide was useful and you have learned how to install Python Linux. Please let us know what we want to explore next. For any suggestions or queries, mention them in the comments section.

Leave a Comment

Your email address will not be published. Required fields are marked *