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

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

Python 3.7 was a significant release for the language. It introduced data classes, a decorator that automatically…

1 hour ago

Install Odoo 13 on Ubuntu 18.04: Python Venv and Nginx Guide

Odoo is a popular open-source suite of business applications. A single platform covers CRM, e-commerce, accounting,…

1 hour ago

Secure Apache with Let’s Encrypt on Ubuntu 18.04: Free SSL Guide

Let's Encrypt is a free, automated certificate authority run by the Internet Security Research Group…

1 hour ago

Install GCC on Ubuntu 18.04: C and C++ Compiler Setup Guide

GCC (GNU Compiler Collection) is a set of compilers and development libraries for C, C++, Fortran,…

1 hour ago

Install Tomcat 9 on Ubuntu 18.04: Systemd Service Setup Guide

Apache Tomcat is an open-source Java application server that implements the Java Servlet, JavaServer Pages, and…

24 hours ago

Change Timezone on Ubuntu 18.04: Command Line and GUI Methods

Setting the correct timezone on your Ubuntu machine is more important than it sounds. Your…

24 hours ago