Ubuntu – How to change the default python on the Ubuntu 20.04 to Python3.8

bashbashrcpython

I would like to set python 3.8 as default on my PC
Thinkpad X230
Ubuntu 20.04

I tried setting an alias

gt@gt-ThinkPad-X230:~$ alias python='usr/bin/python3.8'

Q: Does this alter a .bashrc file? If so, which?
~/.bashrc?
another?
if so, which?

gt@gt-ThinkPad-X230:~$ python --version
bash: usr/bin/python3.8: No such file or directory

Complains it cannot find /usr/bin/python3.8, buuuuut:

gt@gt-ThinkPad-X230:~$ ls /usr/bin/python*

/usr/bin/python /usr/bin/python3.8 /usr/bin/python3-pasteurize
/usr/bin/python2 /usr/bin/python3.8-config /usr/bin/python3-unidiff
/usr/bin/python2.7 /usr/bin/python3-config
/usr/bin/python3 /usr/bin/python3-futurize

How do I get bash to find see /usr/bin/python3.8?

Best Answer

Firstly to answer your question, your approach should work, I think the path you've given in your alias needs the / preceding the path so the command should be alias python='/usr/bin/python3.8', this would indeed need to go into your ~/.bashrc file assuming you are using bash.

Secondly, Ubuntu has a really nice method of setting default binaries globally rather than messing with dot config files as depicted here: update-alternatives

a better solution may be to simply run:

sudo update-alternatives  --set python /usr/bin/python3.8

This will ensure you have the version of python in use that you intend, everywhere.

Related Question