How to remove Python 2 from Ubuntu 20.04?

I've upgraded recently from Ubuntu 18.04 to 20.04. But I can see that Python2 is still the default instead of python 3.8.2.

$ python -V

Python 2.7.18rc1

$ python3 -V

Python 3.8.2

Is it possible to remove python 2 and replace it with Python 3.8?

EDIT: I have always used the following aliases in my ubuntu 18.04:

alias python='python3'
alias pip='pip3'

After upgrading, I removed those aliases because I thought python2 should no longer be there but it is still there.

Thanks


Solution 1:

Before proceeding make sure that you do not really have packages which depend on Python 2.

Then you need to install special package which set aliases for you:

sudo apt-get install python-is-python3

And optionally remove all trails of Python 2 packages manually by

sudo apt-get autoremove --purge

Solution 2:

As user 'N0rbert' answered, you should install 'python-is-python3' to set aliases. And then check the packages that depend on python2 before removing them.

As with my experience with ubuntu 20.04 LTS, only python3 was installed, and I installed python2 by mistake. So, it was relatively easy to uninstall python2.

To uninstall, enter following commands in terminal:

sudo apt remove python2 --simulate
sudo apt remove python2
sudo apt autoremove --purge

Break-down of above commands:

sudo apt remove python2 --simulate: perform a simulation of events that would occur but do not actually change the system.

This would print details of what might happen if you remove python2 from the system. If you are satisfied with the result(outcome) then you may do actual remove by: sudo apt remove python2 and then sudo apt autoremove --purge to remove the configuration files and the unused packages.

Hope it helps you.