Tutorials

Install Python 3.8 on Ubuntu 18.04: apt and Source Build Methods

Python is one of the most widely used programming languages in the world. Its clean, readable syntax makes it easy to learn, and its versatility makes it useful for everything from quick automation scripts to large-scale machine learning systems.

Python 3.8 brought several useful additions to the language, including the walrus operator (:=) for assignment expressions, positional-only function parameters, and improvements to f-strings. It is not available in Ubuntu’s default repositories, so you need to install it separately.

This guide covers two ways to install Python 3.8 on Ubuntu 18.04. If you just need Python 3.8 running quickly and are comfortable with a third-party PPA, use Method 1. If you are setting up a production server and prefer to avoid external repositories, Method 2 builds it directly from source.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Method 1: Install Python 3.8 on Ubuntu Using apt

Installing from the deadsnakes PPA is the fastest option. It gives you a pre-built package with no compilation needed.

Update the package list and install the prerequisites:

bashsudo apt updatesudo apt install software-properties-common

Add the deadsnakes PPA to your system:

bashsudo add-apt-repository ppa:deadsnakes/ppa

Press Enter when prompted to confirm.

Install Python 3.8:

bashsudo apt install python3.8

Verify the installation:

bashpython3.8 --version

Output:

Python 3.8.0

Python 3.8 is now installed alongside your existing Python versions. Your default python3 binary is unchanged.

Method 2: Build Python 3.8 from Source

Building from source gives you a clean, self-contained install with no reliance on external PPAs. It takes longer, but it is the right choice for controlled server environments.

Install the build tools and all required development libraries:

bashsudo apt updatesudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

Download the Python 3.8 source code from the official Python website:

bashwget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

Extract the archive. This creates a Python-3.8.0 directory in your current location:

bashtar -xf Python-3.8.0.tgz

Switch into the source directory and run the configure script. The --enable-optimizations flag runs a set of internal tests to tune the binary for better runtime performance. It makes the build slower but produces a faster interpreter:

bashcd Python-3.8.0./configure --enable-optimizations

Start the build process. The -j flag sets the number of parallel compile jobs. Set it to match your CPU core count for a faster build. To check your core count, run nproc:

bashmake -j 8

Install the Python binaries using altinstall:

bashsudo make altinstall

The altinstall command installs Python 3.8 as python3.8 without touching the existing python3python, or pip symlinks. Using the standard make install would overwrite your system Python and break tools that depend on it.

Verify the installation:

bashpython3.8 --version

Output:

Python 3.8.0

Python 3.8 is now installed and ready to use on your Ubuntu 18.04 machine. The next steps are to set up pip for package management and create Python virtual environments to keep dependencies isolated between projects. Leave a comment below if you run into any build errors.

Cyber Defence

Recent Posts

xargs Command in Linux: Build and Execute Commands from Input

The xargs command in Linux reads items from standard input and passes them as arguments to another…

2 days ago

locate Command in Linux: Find Files Fast with a Database Search

The locate command in Linux searches for files and directories by name. It queries a pre-built database…

2 days ago

Listing Linux Services with systemctl: A Complete Guide

Most modern Linux distributions use systemd as the default service manager. Knowing how to list…

2 days ago

How to Truncate Files in Linux: Empty Files Without Deleting

Truncating a file in Linux means removing its contents while leaving the file itself in…

2 days ago

ss Command in Linux: Display Socket Statistics and Connections

The ss command in Linux lists open sockets and active network connections. It replaced the deprecated netstat command and…

3 days ago

ftp Command in Linux: Connect to Servers and Transfer Files

The ftp command in Linux connects to a remote FTP server and transfers files. FTP transmits everything…

3 days ago