How to install Python in Ubuntu?

Python is a powerful, open-source and easy to learn programming language. It is one of the most popular modern programming languages with a huge community of developers and extensive documentation.

Python usually comes pre-installed on all latest Linux systems as it is one of the building blocks of many operating system tools. However, based on user requirements, you can install specific versions of Python from available sources.

In this tutorial, we will show you two ways to install Python on an Ubuntu system:

  • Installing Python using package manager (apt)
  • Installing Python using its source code

Using Package Manager (apt)

The easiest way to install Python on Ubuntu is using the built-in package manager. This method installs Python from Ubuntu's official repositories.

On Ubuntu, open a Terminal window and execute the following commands:

$ sudo apt update
$ sudo apt install python3

These commands will update your system's repository data and install the available Python 3.x package, if not already installed.

$ sudo apt install python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3 is already the newest version (3.10.6-1~22.04.1).
python3 set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

Installing Specific Python Versions

If you need a specific version of Python, specify its version in the command:

$ sudo apt install python3.11
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
   libpython3.11-minimal libpython3.11-stdlib python3.11-minimal
Suggested packages:
   python3.11-venv python3.11-doc binfmt-support
The following NEW packages will be installed:
   libpython3.11-minimal libpython3.11-stdlib python3.11 python3.11-minimal
0 upgraded, 4 newly installed, 0 to remove and 3 not upgraded.
Need to get 5679 kB of archives.
After this operation, 20.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]

If the specific version of Python is not available from the repository, you can use the source installation method below.

Installing Python from Source Code

Installing Python from source code gives you access to the latest versions and custom configurations. This method is more complex but provides greater flexibility.

Installing Build Dependencies

First, install the required build tools and dependencies:

$ sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

Downloading Python Source Code

Visit the official Python website at python.org/downloads and navigate to the source releases section. Download the desired Python version using wget:

$ wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz

Building and Installing

Extract the downloaded source code:

$ tar xvzf Python-3.13.0.tgz
$ cd Python-3.13.0/

Configure the build with optimizations enabled:

$ ./configure --enable-optimizations

Start the build and installation process:

$ sudo make install

This process takes several minutes depending on your system. Once complete, verify the installation:

$ python3.13 --version

Comparison of Installation Methods

Method Difficulty Version Control Best For
Package Manager Easy Limited to repository versions General use, beginners
Source Code Advanced Any available version Latest versions, custom builds

Conclusion

Installing Python via the package manager is the recommended approach for most users due to its simplicity and automatic dependency management. Use source installation only when you need specific versions not available in the repositories or require custom compilation options.

Updated on: 2026-03-27T16:47:50+05:30

504 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements