How to Install Python on Ubuntu
Python is a high-level, general-purpose programming language that is widely used throughout the IT Industry. It is also one of the most popular in use today. It’s renowned for its versatility and beginner-friendly syntax and has become a cornerstone of modern software development, data science, and automation.
So many everyday applications are programmed in Python that it’s essential to have the Python runtime installed on your Linux server.
This guide provides a comprehensive walkthrough of the different methods for installing Python on Ubuntu, empowering you to choose the approach that best suits your needs and technical expertise. From the simplicity of APT to the flexibility of compiling from source, we’ll explore how to use each method, ensuring a smooth and successful Python installation.

Procedure: Installing Python on Ubuntu
Objective: To outline the various methods for installing Python on an Ubuntu system.
Prerequisites:
- An Ubuntu system with an active internet connection.
- Access to a terminal window.
- Administrative privileges (sudo access).
Using APT to Install:

This is the recommended and simplest method for installing Python.
Step 1: Update the package repository.
APT is the Advanced Package Tool used by Ubuntu-type distributions.
sudo apt updateStep 2: Install Python
Install the desired Python version. Replace [version] with the specific version number (e.g., 3.10, 3.11).
If you are not sure which version you want to install, you can find further information on the Python website.
sudo apt install python3Step 3: Verify the installation.
Now we need to verify the installation has worked correctly
python3 --versionInstalling from Source Code:

This method provides more control over the installation process and is useful for specific needs or when the desired version is not available in the repositories.
Step 1: Update local repositories.
This command refreshes the list of available software packages in your system’s package manager. It ensures you have the latest information about available software, including any updates or new versions.
sudo apt updateStep 2: Install supporting software.
This installs essential tools and libraries required to build software from source code. Python relies on these components for various functionalities. Here’s a brief overview:
build-essential: Provides core tools like a compiler (gcc), make, and other utilities necessary for compiling code.zlib1g-dev: Library for data compression.libncurses5-dev: Library for terminal-based interfaces.libgdbm-dev: Library for database management.libnss3-dev: Libraries for network security services.libssl-dev: Libraries for secure communication.libreadline-dev: Library for command-line editing.libffi-dev: Library for foreign function interfaces.libsqlite3-dev: Library for the SQLite database.wget: Tool for downloading files from the internet.libbz2-dev: Library for bzip2 compression
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-devStep 3: Use wget to download Python
Download the desired Python version’s source code from the official Python website. This example with download Python 3.13 Source Tarball
wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgzStep 4: Extract the downloaded archive.
Now use the tar command to extract the archive file
tar -xzf Python-3.13.0.tgzStep 5: Configure the build.
This script prepares the Python source code for compilation on your specific system. –enable-optimizations tells it to optimize the Python build for better performance.
./configure --enable-optimizationsStep 6: Compile the source code.
This command compiles the Python source code into machine-readable instructions, creating the necessary executable files.
makeStep 7: Install Python.
This installs the compiled Python binaries into your system. altinstall is used to avoid overwriting the default Python installation that might already exist on your system. This allows you to have multiple Python versions installed side-by-side.
sudo make altinstallStep 8: Verify the installation.
This checks that Python was installed correctly and displays the version number of the Python you just installed.
python[version] --versionPost-Installation:
- pip: Ensure
pipis installed, as it is the recommended package installer.
sudo apt install python[version]-pip- Virtual Environments: Consider using virtual environments to isolate project dependencies and avoid conflicts.
python[version] -m venv [environment name]Note: Replace [version] with the specific Python version you are installing.
This procedure provides a comprehensive guide to installing Python on Ubuntu using different methods. Choose the method that best suits your needs and follow the steps carefully.
Check out our other Tech Quicky content here.

Recent Comments