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.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s