From Artificial Intelligence/Machine Learning to Web Development, Python is used almost everywhere and is currently one of the world’s most popular programming languages.
Now that everyone wants to learn how to code, most people start their coding journey learning Python because of its less overwhelming syntax than other programming languages. Soon Python will clinch the spot of Java to become number one in the most popular programming languages list. Let’s install Python on Linux in this article.
If you’re a Python developer/learner who stumbled upon Linux, wondering how to install Python, here’s how you can do it effortlessly. Most of the Linux distributions ship with Python preinstalled and check the version of Python and if it’s installed, type the following command in the terminal.
Install Python on Linux Via Terminal
The only Linuxes in which Python can be installed via the terminal are Debian-based distros and Arch-based distros. For distros like CentOS, Fedora, and OpenSUSE, one needs to build Python.
On Debian-Based Distributions
> To install Python on Debian-based Linux distributions like Ubuntu, all you need to do is type the following command in the terminal
sudo apt update && sudo apt upgrade && sudo apt-get install python3
On Arch-Based Distributions
> To install Python on Arch-based distributions like Manjaro, enter the following command in the terminal.
pacman -S python3
Install Python on OpenSUSE, CentOS, and Fedora via Source
> Install the development tools in YaST or by using Zypper. Type the following command in the terminal and hit enter. This might take a significant amount of time to complete, so wait patiently.
sudo zypper install -t pattern devel_C_C
> Get the source code of the latest Python release from here. You can choose the version you want to download from the list.
> Download the XZ Compressed Tarball and remember the directory you saved it in which, in my case, was “/Downloads”
[email protected]:cd Downloads [email protected]:~/Downloads$
> Now, type the following command in the terminal
tar -xf Python-3.x.y.tar.xz
Where x and y refer to the latest releases’ numbers (Example: 3.9.0), make sure to rename it to the version that you download.
> cd into the Python-3.x.x folder that was created because of the previous command. Your terminal will look something like this.
[email protected]:~/Downloads$ cd Python-3.9.0/ [email protected]:~/Downloads/Python-3.9.0$
> Now, enter this command to configure the build
> Finally, enter this command to install Python
sudo make install
This will take around 2-5 minutes. After it’s done installing, check if Python has been installed using the following command. This is what you’ll see.
[email protected]:~$ python3 --version Python 3.9.0
On CentOS and Fedora
The installation procedure is almost similar to that of Open SUSE except in the first step we used Zypper to install Development tools, but in CentOS and Fedora, we use the in-built package manager yum.
> Updating the yum package manager
sudo yum -y update
> Installing the development tools and dependencies
sudo yum -y groupinstall "Development Tools" sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel
The rest of the process is the same as what was done in Open SUSE starting from installing the Tarball from the official Python website, extracting, and installing it.
Using Python Online
Repl.it is one of my favorite online code IDE/ code compilers. The main idea is to allow users to build apps and websites using a browser.
It also lets you code collaboratively and save your “Repls.” Hence, it basically acts like Github but with a code compiler. Additionally, it also supports over 50 programming languages.