How to install Python 3 and Pip3 in Ubuntu 16

This is the easiest way to install Python 3 on Ubuntu 16 server and making it the default program to run Python 3.

Update first your system

sudo apt-get update

Install prerequisite

sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev

sudo apt-get install python-pip python3-pip python3-dev -y

Making Python to execute Python3

A simple safe way would be to use an alias:

sudo nano ~/.bashrc

and add this code on the top:

alias python=python3

To apply the changes, run this:

source ~/.bashrc

Lets check the changes:

python --version

The return should be something like this:
Python 3.4.3

Making Pip3 as the default pip

sudo nano ~/.bashrc

Paste this code on the top:

alias pip='pip3'

Now let’s apply the changes:

source ~/.bashrc

Check the changes if applied:

pip --version

You should see something like this:
pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)

Leave a Reply

Your email address will not be published. Required fields are marked *