0
votes

I have Python3.6 and Python3.8 installed on Ubuntu 18.04. When I execute python3 -V I get python3.8.0, which is correct. That's currently my default Python.

I used the Ubuntu 18.04 package repository when I installed Python3.6 and Python3.8. I just built Python3.10 from source and I want to set that as the default now. The canonical way to change is with --update-alternatives, but I did not do that when I installed Python3.6 and Python3.8, so when I execute:

update-alternatives --query python
update-alternatives: error: no alternatives for python

Python3.8 is in /usr/bin/python3.8 and Python3.10 is in /usr/local/bin/python3.10.

According to what I have read on the net, I should do this:

$ sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.8
$ sudo update-alternatives --install /usr/local/bin/python python /usr/local/bin/python3.10  

Then I select the default with sudo update-alternatives --config python.

Because I currently don't have any alternatives but I was somehow able to switch from Python3.6 to Python3.8 (I don't remember how), will the commands above cause any problems? Is there a problem in the different locations for 3.8 (/usr/bin/) vs 3.10 (/usr/local/bin/) and what will be the effect of the symlink for 3.10 going into /usr/local/bin/ where it's already located.

Naturally I could just try it, but if there is an issue I'm not sure how to back out of it if it goes wrong. I've gotten a lot of differing information on the net.

Thanks for any help.

1
update-alternatives is mostly for distro-provided packages. For locally-installed stuff, try just putting some extra symlinks into /usr/local/bin, and making sure it's earlier in $PATH - o11c
Be aware that there are also tools like pydoc and pip to worry about. For this reason, I recommend getting into the habit of always using pythonX.Y -m pip, but if you're doing a /usr/local install you could add the extra symlinks if you want. - o11c

1 Answers

0
votes

I have answered my own question. First, I did have alternatives, but as Ubuntu defaults to Python2 (please Ubuntu change that -- the world has moved on), the command is sudo update-alternatives --config python3:

$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

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

Note the line "providing /usr/bin/python3." That means the Python symlinks for Python 3 are in /usr/bin/python3. So I add the new one:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 3

That makes Python 3.10 priority 3, the highest priority. Then:

$ python3 --version
Python 3.10.0   

I hope that helps someone in the future.