Python is a well-known high-level scripting language that many developers prefer worldwide. It is widely used in various applications, including web scraping and web development.
Python has become popular due to its simple and easy-to-read syntax. Due to its ease of learning and usage, you can write and execute Python code faster than many other programming languages. Hence, getting your hands on Python programming language and installing it on your system is a good idea.
In this guide, we will give you a brief on the methods you can use to install Python on Linux.
How to Install Python on Linux?
You can install Python for free because it is an open-source programming language. However, please check the following prerequisites before installation:
- System running on Fedora OS/Debian with a minimum of 2GB of RAM (4GB preferred) and 5GB of disk space.
- Sudo access in the system.
First, check if Python has already been installed on your system, you can do so by running the following command in Terminal:
python -V
or
python –version
If it detects the Python utility, the terminal will print the following details:
You can install Python on your Linux through several methods. Here, we will discuss some of them.
1. Install Python Using the Package Manager
You can install the latest Python version on almost every distribution of Linux using certain commands.
On Fedora
sudo dnf install dnf-plugins-core (dnf-based systems)
sudo dnf builddep python3
sudo yum install yum-utils (yum-based systems)
sudo yum-builddep python3
On Ubuntu
sudo apt-get install python3
Note: Python3 is the latest version of Python, so we use ‘python3’ in the above command.
Suppose you want a specific version of Python and install it on your Linux system. So, you can mention the desired version of Python in the command.
As you can see, Python is already installed in our Linux system, but its version 2.7 is not updated. The latest version of Python is 3.9, so we install it by running the following command:
sudo apt install python3.9
To continue, type ‘y’ and press enter. It will install the latest version of Python on your system through the package manager.
2. Install Python Using Source Code
You can also install Python in your Linux through the source code, but make sure you already have gcc, git, and make on your system.
Get the Source Code First
If git is not installed in your system, install it through the following command.
sudo apt install git
Now, we will clone the latest Python source code from the official GitHub repository.
git clone https://github.com/python/cpython
Configure the Downloaded Source Code
First, navigate the directory where the Python source code is cloned through the following command:
cd cpython
To configure the downloaded source code, run the following command:
./configure –prefix=$HOME/python3.9
Similarly, you can also add the –enable-Optimizations flag to optimize the configuration:
./configure –enable-optimizations –prefix=$HOME/python3.9
This is how your Python source code is configured.
Install the Python
Now you can install Python once you successfully configure its source code. Install Python using the following ‘make’ command:
make install
You can place the file created by the above command at the location specified by configure’s –prefix.
You can check the Python version after completing the installation process in your Linux system with the following commands:
python -V
or
python –version
Conclusion
Python is already installed as part of the default package in almost all Linux distributions. Sometimes Python may not be unavailable on your Linux system. So, you can easily install Python on Linux by following the steps mentioned above. Also, you can configure, install, and run Python on a Linux system as discussed in this guide.
Aditya is a seasoned JavaScript developer with extensive experience in MEAN stack development. He also has solid knowledge of various programming tools and technologies, including .NET and Java. His hobbies include reading comics, playing games, and camping.