I recently installed python3 on my vps, I want to enable it as default, so that when I type
python
I get python 3. I think the problem is its installed in /usr/local/bin
instead of /usr/bin/ typing python
on the terminal access python2 typing python3
returns bash: python3: command not found
Most answers I have seen is a bit confusing as I am not a centos expert.
2
Answers
There’re several ways.
First, check if
/usr/local/bin
isn’t in your $PATH variable:If it is indeed not there, you may want to add this line to your
.bashrc
file (assuming you’re using bash):This will add
/usr/local/bin
to your $PATH variable and will makepython3
accessible after you relaunch a terminal session.Now, changing the default
python
globally might not be a good a idea as there could be system software depending onpython
command pointing to python2.What you could do is use PyEnv which will allow you using different python versions on your computer: https://github.com/pyenv/pyenv
for a simple fix, you can use alias
add the alias to your .bashrc file
sudo vi ~/.bashrc
then add your alias at the bottom
alias python="python3.9"
So that when you type python you’ll get python 3