In this article, we will upgrade to the newest python version and configure it as the default version of python. Here we use “Upgrade python 3.6 to 3.8” as an example.
Start with checking the currently installed version of Python on your system.
$ python3 -V
Python 3.6.9
$ sudo apt-get update
Step 2: Verify the updated Python packages list using this command.
$ apt list | grep python3.8
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
idle-python3.8/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 all
libpython3.8-dbg/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
libpython3.8-dev/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
libpython3.8-minimal/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.4 amd64 [installed,automatic]
libpython3.8-stdlib/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.4 amd64 [installed,automatic]
libpython3.8-testsuite/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 all
libpython3.8/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.4 amd64 [installed,automatic]
python3.8-dbg/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
python3.8-dev/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
python3.8-doc/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 all
python3.8-examples/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 all
python3.8-full/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
python3.8-minimal/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.4 amd64 [installed,automatic]
python3.8-venv/focal-updates,focal-security 3.8.10-0ubuntu1~20.04.4 amd64
python3.8/focal-updates,focal-security,now 3.8.10-0ubuntu1~20.04.4 amd64 [installed,automatic]
Step 3: Install the new Python package using apt-get.
sudo apt-get install python3.8
Step 4: Add old and new version of Python to update-alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
Step 5: Update Python 3 for point to Python new version.
Type this command to configure 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
Press <enter> to keep the current choice[*], or type selection number: 2
You should get the above output. Now type 2 and hit enter for Python 3.8. Remember the selected number may differ so choose the selection number which is for **Python 3.**8.
Step 6: Test the version of python
Finally, test the current version of python by typing this and You should get new version of python ****as output.
$ python3 -V
Python 3.8.1