Article

Table of Contents
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $300 by adding new articles!

How to Install Python 2 on Ubuntu 20.04

Last Updated: Thu, Apr 23, 2020
Python Ubuntu

Introduction

Python 2 has been removed from Ubuntu 20.04, but if you have legacy programs that require the older Python, it's still possible to install and configure.

Step 1: Install Python 2

SSH to your Ubuntu 20.04 server and install Python 2 with apt.

$ sudo apt install python2

Check the Python version.

$ python2 -V
Python 2.7.17

Step 2: Check Available Python Versions

Check what Python versions are available on system.

$ ls /usr/bin/python*
/usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.8

See if there are Python alternatives configured.

$ sudo update-alternatives --list python
update-alternatives: error: no alternatives for python

Step 3: Set Alternate Versions

For this example, we will set two Python alternatives: Python2 and Python3.

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

Confirm that both alternatives are ready to be used:

$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3

Select the alternative Python version.

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   2         auto mode
  1            /usr/bin/python2   1         manual mode
  2            /usr/bin/python3   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 1

Enter your selection. In this example, choose 1 to select Python 2.

Check your python version:

$ python -V
Python 2.7.18rc1

Conclusion

Even though Python 2 is deprecated, it's still possible to install and use with your Vultr VPS running Ubuntu 20.04.

Want to contribute?

You could earn up to $300 by adding new articles