Steps to Install Python in Ubuntu

In this article, we’ll explain steps to install python in Ubuntu. Steps to Install Python in UbuntuIn some of the old Ubuntu version python 3.5 is pre-installed. But in the latest Ubuntu version, python 3.6 is pre-installed by default such as Ubuntu 18.04 and Ubuntu 17.10. If you are using the old Ubuntu version then follow the below steps:

Steps to Install Python in Ubuntu

Step 1: Check the default python binaries on your Ubuntu system

root@sysadminxpert:~# ls -l /usr/bin/python*

lrwxrwxrwx 1 root root       9 Dec 21  2013 /usr/bin/python -> python2.7

lrwxrwxrwx 1 root root       9 Dec 21  2013 /usr/bin/python2 -> python2.7

-rwxr-xr-x 1 root root 3345416 Jun 22  2015 /usr/bin/python2.7

-rwxr-xr-x 1 root root     975 Jan  2 2014 /usr/bin/python2-jsondiff

-rwxr-xr-x 1 root root    1080 Jan  2 2014 /usr/bin/python2-jsonpatch

lrwxrwxrwx 1 root root       9 Mar 23  2014 /usr/bin/python3 -> python3.4

-rwxr-xr-x 2 root root 3693512 Sep 14  2016 /usr/bin/python3.4

-rwxr-xr-x 2 root root 3693512 Sep 14  2016 /usr/bin/python3.4m

lrwxrwxrwx 1 root root      10 Mar 23  2014 /usr/bin/python3m -> python3.4m

root@sysadminxpert:~#

Step 2: Install Python 3.6 version in Ubuntu

$ sudo add-apt-repository ppa:deadsnakes/ppa

$ sudo apt update

$ sudo apt install python3.6

Again check the default python binaries on your Ubuntu system you will see python 3.6 along with 2.7 version.

You can also download python package from official page.

$ ls -l /usr/bin/python*

Output for Python binaries:

root@sysadminxpert:~# ls -l /usr/bin/python*

lrwxrwxrwx 1 root root       9 Dec 21  2013 /usr/bin/python -> python2.7

lrwxrwxrwx 1 root root       9 Dec 21  2013 /usr/bin/python2 -> python2.7

-rwxr-xr-x 1 root root 3345416 Jun 22  2015 /usr/bin/python2.7

-rwxr-xr-x 1 root root     975 Jan  2 2014 /usr/bin/python2-jsondiff

-rwxr-xr-x 1 root root    1080 Jan  2 2014 /usr/bin/python2-jsonpatch

lrwxrwxrwx 1 root root       9 Mar 23  2014 /usr/bin/python3 -> python3.4

-rwxr-xr-x 2 root root 3693512 Sep 14  2016 /usr/bin/python3.4

-rwxr-xr-x 2 root root 3693512 Sep 14  2016 /usr/bin/python3.4m

-rwxr-xr-x 2 root root 4555968 Dec 25  2018 /usr/bin/python3.6

-rwxr-xr-x 2 root root 4555968 Dec 25  2018 /usr/bin/python3.6m

lrwxrwxrwx 1 root root      10 Mar 23  2014 /usr/bin/python3m -> python3.4m

root@sysadminxpert:~#

From this above output, the default python version on your system is 2.7.

Step 3: Check the Python version:

$python -V

Demo Output:

root@sysadminxpert:~# python -V

Python 2.7.6

root@sysadminxpert:~# python3.6 -V

Python 3.6.8

root@sysadminxpert:~#

If you want to use the latest Python 3.6 version, then use the following command:

root@sysadminxpert:~# python3.6 -V

Python 3.6.8

root@sysadminxpert:~# python3.6

Python 3.6.8 (default, Dec 25 2018, 00:00:00)

[GCC 4.8.4] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>>

>>> exit()

root@sysadminxpert:~#

How to exit a Python Interpreter?

exit()

or

quit()

Thanks for reading this articles.

This is the end of the article, Steps to Install Python in Ubuntu.

See more on Linux Blog

Steps to Install PIP in Amazon Linux or RHEL or CentOS