Skip to content

Instantly share code, notes, and snippets.

@kentblake
Last active June 20, 2020 10:03
Show Gist options
  • Save kentblake/6910dd256f989abb41af30a8eeb01237 to your computer and use it in GitHub Desktop.
Save kentblake/6910dd256f989abb41af30a8eeb01237 to your computer and use it in GitHub Desktop.
Update alternatives syntax for changing from python2.7 to python3.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2
@kentblake
Copy link
Author

kentblake commented Jan 9, 2018

Did more RTFM and discovered that I was indeed able to change default python, just not using the syntax that I was guessing at.

This entire gist is from reading in the "Debian Administrator's handbook:"
https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux

The --install option take multiple arguments from which it will be able to create a symbolic link. The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for /usr/bin/python3.4 and as a result the /usr/bin/python3.4 was set as default python version automatically by update-alternatives command.

So I am taking the || pseudo-code out because both commands are necessary. Also please note that the versions are as of this date and you may need to change them as python3 versions will increment. If you are on python2.7, we already know there will be no further development on that platform other than patches or security updates, so the only time you would need to modify will be for python3 revisions, etc.

Now for what I learned:

update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.7
update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.7   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.7   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 

`
Fantastic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment