Python is one of the most widely used programming languages today. Whether you are a beginner or an experienced developer, knowing how to install Python on Linux is an essential skill. Linux offers a variety of ways to install Python, from using package managers to installing from source. This guide will walk you through the entire process, providing you with step-by-step instructions for different Linux distributions.
In this article, we will cover:
- How to install Python on Linux via the terminal.
- Installing Python on popular Linux distributions like Kali Linux, Linux Mint, and Debian.
- The process of installing Python from a tarball.
- Managing Python versions on Linux.
By the end of this guide, you’ll have Python up and running on your Linux system, and you’ll be equipped to begin coding, running scripts, or developing Python applications with ease.
Why Python is Important on Linux?
Before diving into the installation process, it’s essential to understand why Python is such a valuable tool on Linux. Python is not only one of the most beginner-friendly programming languages, but it is also powerful and flexible. It’s used in a wide array of applications, from web development and data analysis to machine learning and system administration.
On Linux, Python is often pre-installed in many distributions, as it’s required for running various system utilities and scripts. Whether you’re a beginner or an experienced developer, mastering Python on Linux is vital to harnessing the full potential of this operating system.
How to Install Python on Linux (General Steps)
Installing Python on Linux can be done in a few simple steps. While Linux systems come with Python pre-installed, it’s often beneficial to install a newer version or set up multiple versions on your machine. Here are the general steps to install Python using the terminal.
Using the Linux Command Line
- Open the Terminal
The terminal is your command center for installing and managing software on Linux. To open the terminal, simply pressCtrl + Alt + T
or search for “Terminal” in your applications. - Update Your System
It’s a good idea to make sure your system is up to date before installing Python. Run the following command to update your system’s package list:sudo apt update
- Install Python
Most Linux distributions use package managers likeapt
oryum
. Depending on your system, use one of the following commands:- For Ubuntu/Debian-based systems (including Kali Linux, Linux Mint, and Debian):
sudo apt install python3
- For Red Hat-based systems (including CentOS or Fedora):
sudo dnf install python3
- For Ubuntu/Debian-based systems (including Kali Linux, Linux Mint, and Debian):
- Verify the Installation
After installation is complete, you can verify that Python was installed correctly by typing:python3 --version
You should see the version number of Python printed on the terminal.

Installing Python on Kali Linux
Kali Linux is a Debian-based distribution primarily used for penetration testing and security research. Python is an essential tool in Kali, as it’s used for various automation tasks and writing exploits. Here’s how to install Python on Kali Linux:
- Open the Terminal
PressCtrl + Alt + T
or open the terminal from your applications menu. - Update Kali Linux
It’s always a good idea to ensure your system is up to date before installing software:sudo apt update && sudo apt upgrade
- Install Python
To install the latest version of Python 3 on Kali Linux, run:sudo apt install python3
- Verify the Installation
You can check if Python is successfully installed by running:python3 --version
You should see something likePython 3.x.x
printed on the terminal.
How to Install Python on Linux Mint?
Linux Mint is another popular Linux distribution based on Ubuntu. Installing Python on Linux Mint follows similar steps to Ubuntu and Debian. Here’s how you can do it:
- Open the Terminal
Open the terminal by pressingCtrl + Alt + T
or searching for it in the menu. - Update Your System
As with any installation process, it’s best to update your package list:sudo apt update
- Install Python
To install Python 3, use the following command:sudo apt install python3
- Verify the Installation
To verify the installation, type:python3 --version
The Python version will appear, confirming that the installation was successful.
How to Install Python on Linux Debian?
Debian is the foundation for many Linux distributions, including Ubuntu and Kali Linux. Installing Python on Debian is a straightforward process:
- Open the Terminal
PressCtrl + Alt + T
to open the terminal. - Update Your System
Make sure your system’s package list is updated:sudo apt update
- Install Python
Run the following command to install Python 3:sudo apt install python3
- Verify the Installation
Confirm the installation by checking the Python version:python3 --version
How to Install Python from Tarball?
If you need to install a specific version of Python or prefer not to use a package manager, you can install Python from a tarball. This method involves compiling the source code, which can be useful for advanced users who need a custom setup.
Steps to Install Python from Tarball:
- Download the Python Source Code
Go to the official Python website and download the source tarball of the desired Python version. - Extract the Tarball
Open the terminal, navigate to the folder where the tarball was downloaded, and extract it:tar -xvf Python-3.x.x.tgz
- Install Dependencies
Before compiling, make sure you have the necessary dependencies installed:sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev libffi-dev liblzma-dev
- Compile and Install Python
Navigate into the extracted directory and run the following commands:cd Python-3.x.x ./configure --enable-optimizations make sudo make altinstall
- Verify the Installation
After installation, verify that the new Python version is working:python3.x --version
How to Install Python Modules on Linux Terminal
Installing Python modules is an essential part of Python development. Python’s package manager, pip
, makes it easy to install and manage modules directly from the terminal.
Steps to Install Python Modules:
- Install pip
First, ensure thatpip
is installed by running:sudo apt install python3-pip
- Install a Python Module
Use the following command to install a specific Python module, such asrequests
:pip3 install requests
- Verify the Installation
After installation, you can verify that the module was installed correctly:python3 -c "import requests; print(requests.__version__)"
Managing Multiple Python Versions on Linux
Sometimes, you may need to manage multiple versions of Python on your system for different projects. One popular tool for managing multiple Python versions is pyenv
.
Steps to Install and Use pyenv:
- Install pyenv
First, install the required dependencies:sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl llvm libncurses5-dev libncursesw5-dev libffi-dev liblzma-dev
Then, installpyenv
:curl https://pyenv.run | bash
- Configure Shell
Add the following lines to your shell configuration file (e.g.,~/.bashrc
or~/.zshrc
):export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)"
Restart your terminal or runsource ~/.bashrc
. - Install Python Versions
Usepyenv
to install different versions of Python:pyenv install 3.9.6
- Set Global Python Version
Set the default Python version for your system:pyenv global 3.9.6
Conclusion
Install Python on Linux is a straightforward process, but there are several ways to do it depending on your preferences and needs. Whether you’re using package managers like apt
or dnf
, installing Python from a tarball, or managing multiple versions with pyenv
, Linux provides a variety of tools and methods to make the installation process smooth and flexible.
With Python installed on your Linux machine, you can start exploring the world of Python programming, from web development to data analysis, or simply run Python scripts to automate tasks.
Happy coding! If you have any questions or encounter issues, feel free to leave a comment below.
If you found this guide helpful, don’t forget to share it with your friends or colleagues. Explore more Python tutorials and related content here.