5

I have an older VM of Ubuntu that is running 16.04. On this system I have python3.5 and python3.8 installed. It seems that by default 'python' is being interpreted to mean python2.7 and python3 is set to python3.5. I would like the default to by 3.8, or at least the default python3 changed to python3.8? If I do this is it likely to break anything?

Should I actually delete python3.5? Is there any point in having multiple versions of python3?

wayner
  • 59

1 Answers1

6

Python 2.X packages are named differently than Python 3.X packages in the default Ubuntu repositories, python-... for Python 2.X packages vs. python3-... for Python 3.X packages. The command to start the Python interpreter follows a similar pattern, python for the default Python 2.X version vs. python3 for the default Python 3.X version.

Don't remove the default Python 3.x version because removing it can break a lot of things like the terminal, the Software app and many other apps. For more information see this question: Removed Python 3 and now Ubuntu Software Center, terminal and other applications don't work. The good news is that even if you break those things it is possible to restore the original Python 3.x version by booting Ubuntu into recovery mode, and then Ubuntu will work normally again.

Instead of replacing the default Python 3.x version entirely the recommended way of installing another Python 3.x version is to keep the existing Python 3 and install the new Python 3 version alongside it. Then you can use a program called update-alternatives to select which one of the Python versions you want to use.

Add Python 3.8 to update-alternatives so that you can switch between Python 3.5 and Python 3.8 by running update-alternatives --config python3.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8
update-alternatives --config python3

After you are done using Python 3.8 you can switch the it back to the default Python 3.5 version.

  • List installed versions of Python: update-alternatives --list python

  • Switch between Python versions: update-alternatives --config python

    From the terminal command-line Press <enter> to keep the current choice[*], or type selection number:

karel
  • 114,770
  • OP talks about 16.04 where 2.7 is the default which should not be removed. I guess it's safe to remove any 3.x version. – pLumo Jan 20 '22 at 09:15
  • 2
    Back in 13.04 removing Python 3 broke the Ubuntu Software Center, the terminal, and other applications - link. – karel Jan 20 '22 at 10:08
  • 1
    I can say from past experience that messing with the executables that handle python, python2 or python3 is a very very bad idea. Years ago I (pretty foolishly) symlinked python3 to python, apt quit working. – jrh Jan 20 '22 at 14:07