Cybersecurity Updates & Tools

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.