How to update-alternatives to Python 3 without breaking apt?

前端 未结 4 481
忘掉有多难
忘掉有多难 2020-12-01 03:01

The other day I decided that I wanted the command python to default to firing up python3 instead of python2.

So I did this:

$ sudo update-alternative         


        
4条回答
  •  情书的邮戳
    2020-12-01 03:15

    replace

    [bash:~] $ sudo update-alternatives --install /usr/bin/python python \
    /usr/bin/python2.7 2
    
    [bash:~] $ sudo update-alternatives --install /usr/bin/python python \
    /usr/bin/python3.5 3
    

    with

    [bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
    /usr/bin/python2.7 2
    
    [bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
    /usr/bin/python3.5 3
    

    e.g. installing into /usr/local/bin instead of /usr/bin.

    and ensure the /usr/local/bin is before /usr/bin in PATH.

    i.e.

    [bash:~] $ echo $PATH
    /usr/local/bin:/usr/bin:/bin
    

    Ensure this always is the case by adding

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

    to the end of your ~/.bashrc file. Prefixing the PATH environment variable with custom bin folder such as /usr/local/bin or /opt//bin is generally recommended to ensure that customizations are found before the default system ones.

提交回复
热议问题