I'm using Ubuntu 19.10
, in which there is python of version 3.7
. After the release of python 3.8
, which I have installed, now I want to uninstall python 3.7
so that whenever I would call python3
in my terminal, it would always call python3.8
?

- 4,708
- 8
- 42
- 85

- 344
- 1
- 5
- 11
-
Does https://stackoverflow.com/a/45392626 help? – IamAshKS Dec 14 '19 at 18:23
3 Answers
You do not need to uninstall old version for this. You need to update your update-alternatives , then you will be able to set your default python version.
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
Then run :
sudo update-alternatives --config python
Set python3.6 as default.
Or use the following command to set python3.6 as default:
sudo update-alternatives --set python /usr/bin/python3.6 This should do it.

- 171
- 8
-
1This is better than uninstalling because system services and other programs might be using the older version of python and depending on it on specific version path – Luiz Ferraz Dec 14 '19 at 20:20
-
In case someone needs a more elaborated guide, just change the name of the versions accordingly: https://tech.serhatteker.com/post/2019-09/upgrade-python37-on-ubuntu18/ – r02 Dec 29 '21 at 16:18
I suggest you do not touch your default OS python instalation. Other parts of the system may depend on it and there is no way to know if an upgrade can break something, even if it should not.
I also suggest that you learn (if you haven't already, but I suppose you did not because of the question) about using a python virtual environment, like virtualenv. This allows you to setup specific python environments for each project you write. This means each environment can have its own python version, and, besides the standard python lib for that version, any other third-party python lib you would like to install with pip for that project. This isolates projects from each other. You won't break one because of an upgrade of another.
That said, if you want to keep cutting edge with Python versions, make an install from source, and then install it in the system with the altinstall parameter (see the README.rst of the Python distribution. This way all the installed versions are available with different names (the same for pip) and then you create each of your virtual environments with the wanted version. There is a parameter for virtualenv to apply a specific (older) version if you want.
Quoting the README on the "Installing multiple versions" section:
On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (
--prefix
argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed usingmake altinstall
contain the major and minor version and can thus live side-by-side.make install
also creates${prefix}/bin/python3
which refers to${prefix}/bin/pythonX.Y
. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version usingmake install
. Install all other versions usingmake altinstall
. For example, if you want to install Python 2.7, 3.6, and 3.8 with 3.8 being the primary version, you would executemake install
in your 3.8 build directory andmake altinstall
in the others.
Finally, the other answers are ok to do exactly what you asked, if you still want to.

- 4,714
- 1
- 16
- 27
so that whenever I would call python3 in my terminal, it would always call python3.8
You can simply create an alias for Python 3.8 in your .bashrc
file in your /home
path.
Open ~/.bashrc
with your preferred editor, and go to the last line.
Append this line:
alias python='python3.8'
And whenever you call python
in your terminal, it opens Python 3.8
.
Note: This doesn't work as expected when creating virtual environments with specific version. You might want to keep that in mind.

- 3,255
- 4
- 17
- 36