In this tutorial we’ll install the latest Python 3 on an Ubuntu 18.04 machine.

Python is one of the fastest growing programming languages at the time of writing. It’s easy to learn, fast, and versatile. You can do almost anything with it, and it’s the most popular for machine learning.

Some of the most popular sites and applications are built using Python – Google, Youtube, Instagram, Pinterest and Spotify to name a few.

We’ll install the latest Python 3, on our machine, using two methods. One will be to install the pre-compiled version from the repositories, and the second will be to compile the latest version ourselves, from the source code.

Method #1 – Install the Latest Python 3 from Repositories

This method is the easier way to install the latest version of Python.

Step 1 – Prerequisites

Before installing, first let’s perform all updates, and then check the version currently installed on your machine. To do this run one of the following commands:

$ python3 -V
$ python3 --version

To check if there are multiple versions installed, run the following command to view all versions:

$ apt list --installed | grep python

If you want to install the latest version of Python 3 on your machine, run the following command:

Step 2 – Install the Python 3.x

$ sudo apt-get install python3

If it’s already installed, then you can upgrade to the latest version by running:

$ sudo apt-get upgrade python3

Method #2 – Install the Latest Python 3 from Source Code

This method is more complicated and it takes more time. The advantage to installing Python 3 this way is that you control the installation and it can be more secure at times, depending where the package is downloaded from.

Step 1 – Prerequisites

First off, let’s update our package index.

$ sudo apt-get update

For this method, we’ll need the tools and libraries to build the source for Python. To install them, run the following commands:

sudo apt-get install build-essential
sudo apt-get install libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

Step 2 – Download Python 3.x

Now we’ll need to download the latest version onto our machine. To do this, visit the official Python website, check the Downloads section and click to download Source code. There you’ll see something like Latest Python 3 Release – Python 3.x.x. Follow that link and scroll down to Files. What we want is the link to “Gzipped source tarball”.

At the time of writing, this is the source tarball download link `https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz`. Now let’s download it onto our machine, in `/usr/src`:

cd /usr/src
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz

Next, unzip the tarball:

$ tar xzf Python-3.7.1.tgz

Step 3 — Install Python3.x

Now let’s configure the build and install the build. This will take a while because it will run tests that will optimize the binary to run faster.

cd Python-3.7.1
./configure --enable-optimizations
make
make install

After it’s finished, then Python 3 should be installed.

Conclusion

Now you should have the latest version of Python 3 up and running. If you’ve encountered any issue installing it, then don’t hesitate to let us know in the comments or contact us.

If you’re looking for a reliable high performance Linux VPS to run your scripts, then check out our Linux KVM Plans. Our smallest plan provides you with 2GB RAM, 10GB SSD for only $5.99/mo.


Vlad

Tech Support

LIMITED TIME SPECIAL 💀

Enter your email below to get 20% OFF on any of our Linux VPS plans and receive weekly deals on our services!