Categories
Docker

Default python version to python3 in Ubuntu

I wanted to set set default python version to 3 instead of 2 that is default on Ubuntu 18. I tried add alias to .bashrc like:

alias python=python3

The disadvantage of editing .bashrc file is that it will not work while using the commands with sudo. I am running my Ubuntu image via Docker as root so it is disregarding this alias.

Good and easy way out from this is to run command

update-alternatives --install /usr/bin/python python /usr/bin/python3 10

This gives a priority of 10 for the path of python3.

So, if you are running this on Docker just add

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10

To you Dockerfile.