How to install Python on Linux?
Last Updated :
15 May, 2024
Before we start with how to install Python3 on Linux, let’s first go through the basic introduction to Python. Python is a widely used general-purpose, high-level programming language. Python is a programming language that lets you work quickly and integrate systems more efficiently. There are two major Python versions- Python 2 and Python 3. Both are quite different.
Getting Started with Python
Python is a lot easier to code and learn. Python programs can be written on any plain text editor like Notepad, Notepad++, or anything of that sort. One can also use an online IDE for writing Python codes or can even install one on their system to make it more feasible to write these codes because IDEs provide a lot of features like intuitive code editor, debugger, compiler, etc. To begin with, writing Python Codes and performing various intriguing and useful operations, one must have Python installed on their System.
Check if Python already exists
Most of the Linux OS has Python pre-installed. To check if your device is pre-installed with Python or not, just go to the terminal using Ctrl+Alt+T.
Now run the following command:
For Python2
python --version
For Python3.x
python3.x --version
If Python is already installed, it will generate a message with the Python version available.
Python 3.13 Installation in Linux
Step 1: Updating and Upgrading Operating System
Before Installing Python 3.12 with APT in Linux(Ubuntu) we have to Update Operating System. To update the operating system use the command mentioned below.
sudo apt update

updating OS
To Upgrade the operating system use the command mentioned below.
sudo apt upgrade

Upgrading OS
Step 2: Adding the deadsnakes PPA to your system’s package sources
Deadsnakes PPA is a popular and trusted repository maintained by the Ubuntu community. It offers the latest versions of Python, including development and unstable releases, which may not be available in the official Ubuntu repositories.The purpose of using the deadsnakes PPA is to gain access to the most recent Python versions, as the official Ubuntu repositories often lag behind in providing the latest releases. By adding the deadsnakes PPA to your system’s package sources, you can install the latest Python versions directly from this repository.
Install the prerequisite for adding PPAs:
This command installs the software-properties-common package, which provides a tool called add-apt-repository. This tool is used to add new package repositories (like the deadsnakes PPA) to your system’s sources list.
sudo apt install software-properties-common -y

installing perquisite
Adding deadsnakes PPA:
This command adds the deadsnakes PPA to your system’s package sources list. The ppa:deadsnakes/ppa part specifies the PPA location, which is hosted on Launchpad (a software collaboration platform used by Ubuntu and other distributions).
sudo add-apt-repository ppa:deadsnakes/ppa

Adding deadsnakes PPA

Adding deadsnakes PPA
We have to update apt after we have installed repository.
Sudo apt update
Step 3: Installing Python3.13 in Linux
Now we can install python3.13 using command mentioned below.
sudo apt install python3.13

Installing python 3.13 on Linux
Step 4: Verifying the Installation of python3.13 in Linux
To verify the installation of python3.13 in linux we can simply display the version of python3.13 by using the command mentioned below.
python3.13 --version

verifying the
Step 5: Installing PIP
If you have used apt to install python3.13 then you might have to install pip3.13 version manually , to do so command is mentioned below.
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.13

installing pip3.13 for python3.13
Step 6: Verifying Installation of PIP3.13
To verify the installation of pip3.13 in Linux we can use the command mentioned below.

verifying
Install Python on Linux – FAQs
How can I check if Python is already installed on my Linux system?
You can check if Python is pre-installed on your Linux distribution by opening the terminal and running the following commands:
python --version # For Python 2.x
python3 --version # For Python 3.x
If Python is installed, these commands will display the respective version numbers. If not, you’ll typically get a “command not found” error.
What is the recommended way to install Python on Ubuntu/Debian-based distributions?
The recommended way to install Python on Ubuntu and other Debian-based distributions is to use the Advanced Packaging Tool (APT) package manager. You can install Python 3 with the following command:
sudo apt install python3
This command will install the latest available version of Python 3 from the official Ubuntu repositories.
How can I install a specific version of Python on Linux?
To install a specific version of Python, you may need to add a third-party repository like the deadsnakes PPA for Ubuntu/Debian. After adding the repository, you can install the desired Python version with a command like:
sudo apt install python3.9 # For Python 3.9
Replace “3.9” with the version number you want to install.
What is pip, and how do I install it on Linux?
pip is the package installer for Python, which allows you to install and manage external Python packages and libraries. On most Linux distributions, you can install pip for Python 3 with the following command:
sudo apt install python3-pip
Alternatively, you can download the get-pip.py script and run it with the respective Python version:
curl https://bootstrap.pypa.io/get-pip.py | python3
How can I install Python packages in a virtual environment on Linux?
It’s generally recommended to use virtual environments to isolate Python packages and dependencies for different projects. You can create and activate a virtual environment on Linux using the venv module:
python3 -m venv myenv # Create a virtual environment named 'myenv'
source myenv/bin/activate # Activate the virtual environment
With the virtual environment activated, you can install packages using pip without affecting the system-wide Python installation.
Conclusion
Getting the latest Python3 version up and running on Linux like Ubuntu involves a few easy steps. First, you update the system packages. Then, you add the deadsnakes PPA repository to access the newest Python releases. After that, you can simply install the desired Python3 version using the apt package manager. Finally, you download and install the pip package installer for the specific Python3 version you installed. Once you verify that both Python3 and pip are installed correctly, your system is ready to start using Python3 for coding, scripting, or running Python applications. Following these straightforward steps allows you to quickly set up the latest Python3 environment on your Linux machine.
Please Login to comment...