Skip to content

Instantly share code, notes, and snippets.

@dev-sareno
Last active May 1, 2024 05:37
Show Gist options
  • Save dev-sareno/1d2bf9cad3a0dc281f0bb16d501a4388 to your computer and use it in GitHub Desktop.
Save dev-sareno/1d2bf9cad3a0dc281f0bb16d501a4388 to your computer and use it in GitHub Desktop.

How to Install Python 3.8 on Ubuntu and Debian

Tested on Debian 10 Buster

Prerequisites

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install wget  # For downloading file
$ sudo apt-get install xz-utils  # For extracting .tar.xz files
$ sudo apt-get install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev  # For compiling Python binaries

Step 1 - Download Python 3.8

Python download site: https://www.python.org/downloads/release/python-381/

$ cd /opt
$ sudo wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tar.xz

Step 2 - Extract

$ sudo tar -xf Python-3.8.1.tar.xz

Step 3 - Compile Python

$ ./configure --enable-optimizations
$ make
$ make install

Note: --enable-optimizations will run tests. It will take longer than without it.

Step 4 - Checking installation

$ cd Python-3.8.1
$ python3.8 -V

Old Method

Update: This method might not work on some old versions of Debian and Ubuntu

Note: All the info here is NOT mine. I'm just making a copy of it as my personal reference. Kindly visit the original post.

Original Post: https://tecadmin.net/install-python-3-8-ubuntu/

The Python team has released its latest version Python 3.8 for general use. You can download the latest stable version Python 3.8 series and install it on your system. This article will help you to install Python 3.8.3 on Ubuntu, Debian, and LinuxMint operating system. You can visit here to read more about Python releases.

Step 1 – Prerequisite

As you are going to install Python 3.8 from the source. You need to install some development libraries to compile Python source code. Use the following command to install prerequisites for Python:

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

Step 2 – Download Python 3.8

Download Python source code using the following command from python official site. You can also download the latest version in place of specified below.

$ cd /opt
$ sudo wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

Then extract the downloaded source archive file

$ sudo tar xzf Python-3.8.3.tgz

Step 3 – Compile Python Source

Use the below set of commands to compile Python source code on your system using the altinstall command.

$ cd Python-3.8.3
$ sudo ./configure --enable-optimizations
$ sudo make altinstall

Note: make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

Step 4 – Check Python Version

Check the installed version of python using the following command. As you have not overwritten the default Python version on the system, So you have to use Python 3.8 as follows:

$ python3.8 -V
Python-3.8.3

After successful installation remove the downloaded archive to save disk space

$ cd /opt
$ sudo rm -f Python-3.8.3.tgz

Alternatives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment