How to Install Python 2 on Ubuntu 16.04

Introduction

In this tutorial we’ll learn how to install Python 2 on Ubuntu 16.04. Ubuntu 16.04 (Xenial Xerus) is not shipped with Python 2 by default but it’s available on Ubuntu 16.04 repository.

Install Python 2

We can install python 2 from Ubuntu repository using command below


$ <span class="token function">sudo</span> <span class="token function">apt-get</span> <span class="token function">install</span> python

```

As alternative you can also install package `python-minimal`:


$ <span class="token function">sudo</span> <span class="token function">apt-get</span> <span class="token function">install</span> python-minimal

```

It will give output and question to continue the process. Enter Y.


Reading package lists<span class="token punctuation">..</span>. Done
Building dependency tree       
Reading state information<span class="token punctuation">..</span>. Done
The following additional packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python2.7 python2.7-minimal
Suggested packages:
  python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-minimal python2.7 python2.7-minimal
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,877 kB of archives.
After this operation, 16.6 MB of additional disk space will be used.
Do you want to continue? <span class="token punctuation">[</span>Y/n<span class="token punctuation">]</span>

```

If you want to bypass confirmation above you can pass `-y` option to `apt-get`


$ python
Python 2.7.12 <span class="token punctuation">(</span>default, Nov 12 2018, 14:36:49<span class="token punctuation">)</span> 
<span class="token punctuation">[</span>GCC 5.4.0 20160609<span class="token punctuation">]</span> on linux2
Type <span class="token string">"help"</span>, <span class="token string">"copyright"</span>, <span class="token string">"credits"</span> or <span class="token string">"license"</span> <span class="token keyword">for</span> <span class="token function">more</span> information.
<span class="token operator">>></span><span class="token operator">></span>

```

To exit from Python interactive you can type `CTRL + D`. You can also type `exit()` or `quit()` to exit.

To check python location you can use command below


$ <span class="token function">which</span> python
/usr/bin/python

```

When we checked `/usr/bin/python`, it's actually a symbolic link to `/usr/bin/python2.7`.


$ <span class="token function">ls</span> -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Nov 24  2017 /usr/bin/python -<span class="token operator">></span> python2.7

```

## Summary

In this tutorial we learned how to install Python 2 on Ubuntu 16.04 (Xenial Xerus). This is useful if we still have python app that is not compatible with Python 3 (yet) but we want to run it on Ubuntu 16.04 LTS (Xenial Xerus).