How to set Python3.5.2 as default Python version on CentOS?

muaaz picture muaaz · Aug 7, 2017 · Viewed 81.2k times · Source

Is there a way to set the Python 3.5.2 as the default Python version on CentOS 7? currently, I have Python 2.7 installed as default and Python 3.5.2 installed separately.

I used the following commands

mv /usr/bin/python /usr/bin/python-old
sudo ln -fs /usr/bin/python3 /usr/bin/python

but after that yum gives the error.

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

is there something I'm missing here?

NOTE: its the similar but opposite question of Linux CentOS 7, how to set Python2.7 as default Python version?

Answer

Liam picture Liam · Aug 7, 2017

If this

sudo ln -fs /usr/bin/python3.5 /usr/bin/python

doesn't work (it should)

you could just add an alias into your /home/.bashrcwith this command:

alias python="/usr/bin/python3.5"

and if this does not work either you should just use virtual env. Read this page to get started.