Skip to content

Instantly share code, notes, and snippets.

@AaronMT
Created February 25, 2021 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronMT/62c77895e2e86c0975afe0bc15c1c94d to your computer and use it in GitHub Desktop.
Save AaronMT/62c77895e2e86c0975afe0bc15c1c94d to your computer and use it in GitHub Desktop.
Setting a specific Python3 default on Ubuntu
List available python options
```
ls -larth `which python`*
lrwxrwxrwx 1 root root 10 Mar 23 2016 /usr/bin/python3m -> python3.5m
lrwxrwxrwx 1 root root 9 Mar 23 2016 /usr/bin/python3 -> python3.5
lrwxrwxrwx 1 root root 9 Nov 24 2017 /usr/bin/python2 -> python2.7
lrwxrwxrwx 1 root root 9 Nov 24 2017 /usr/bin/python -> python2.7
-rwxr-xr-x 2 root root 4.3M Nov 28 2017 /usr/bin/python3.5m
-rwxr-xr-x 2 root root 4.3M Nov 28 2017 /usr/bin/python3.5
-rwxr-xr-x 1 root root 3.4M Dec 4 2017 /usr/bin/python2.7
```
We have 2 options available, python2.7 and python3.5 (These are default pythons that came with Ubuntu)
update-alternatives for python/ python2
```
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
```
update-alternatives for python3
```
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python2.7 2
sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python2.7 1 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
```
Done! Commands that requests for python, python2 or python3 will now work properly and say goodbye to errors!
Credit goes to patrickmmartin for his original gist at https://gist.github.com/patrickmmartin/5b6b2ddecd29d6a1b2ffee2d8eea31ec. This gist is just an update for python3 commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment