skip to Main Content

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


  1. There’re several ways.

    First, check if /usr/local/bin isn’t in your $PATH variable:

    echo $PATH
    

    If it is indeed not there, you may want to add this line to your .bashrc file (assuming you’re using bash):

    export PATH="/usr/local/bin:$PATH"
    

    This will add /usr/local/bin to your $PATH variable and will make python3 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 on python 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search