In this article, we will upgrade to python 3.9.0 and configure it as the default version of python in Ubuntu 18.04 LTS.
The current stable version of python released on 14 Oct. 2020. Many ubuntu users are facing problems during upgrading python to the latest version. Python 3.8 available as default when we install Ubuntu 18.04 LTS. Python 3.9.0 is not available in default Ubuntu 18.04 repositories.
Also Read: How to upgrade to Python 3.7 on Ubuntu 18.10
So let’s start with checking the currently installed version of Python on your system.
python3 -V
As seen in the image above, my currently installed Python version is 3.6.9 but yours may differ.
Table of Contents
Install Python 3.9.0
Follow the simple steps to install and configure Python 3.9.0
Step 1: Add the repository and update
Latest Python 3.9 not available in Ubuntu’s default repositories. So, we have to add an additional repository. On launchpad repository named deadsnakes is available for Python Packages.
Add the deadsnakes repository using the below commands.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
Update the package list using the below command.
apt-get update
Verify the updated Python packages list using this command.
apt list | grep python3.9
As seen in the image above, Now we have Python 3.9.0 available for installation.
Step 2: Install the Python 3.9.0 package using apt-get
install Python 3.9.0 by using the below command :
sudo apt-get install python3.9
Step 3: Add Python 3.6 & Python 3.9 to update-alternatives
Add both old and new versions 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.9 2
Step 4: Update Python 3 for point to Python 3.9
By default, Python 3 is pointed to Python 3.6. That means when we run python3 it will execute as python3.6 but we want to execute this as python3.9.
Type this command to configure python3:
sudo update-alternatives --config python3
You should get the above output. Now type 2 and hit enter for Python 3.9. Remember the selected number may differ so choose the selection number which is for Python 3.9.
Step 5: Test the version of python
Finally, test the current version of python by typing this :
python3 -V
You should get Python 3.9 as output.
In this article, we learn how to upgrade python to the latest version that is 3.9.0 in Ubuntu 18.10.
Share your thoughts in the comment section. Happy Learning …!!
Nice thing is to add following command
sudo apt install python3.9-distutils
otherwise you will struggle with once you install pip3, more about that:
https://askubuntu.com/questions/1292972/importerror-cannot-import-name-sysconfig-from-distutils-usr-lib-python3-9
After I completed all the actions indicated in the tutorial, the terminal stopped starting for me.
The python and ubuntu versions are the same as in the article.
I solved this problem by changing the config again, but it was unpleasant experience.
Please educate your readers about these dangers in the future!
Same happened for me
My terminal stopped working. After I did things you said.
Hi Karim, i am new to ubuntu and dont know how to fix this now. Could you guide and please help as what to do now?
My terminal is not opening
Thanks a lot
I suggest you add a disclaimer that this is not an official supported version.
The best way to install a newest version is to use an alternative python 3.9 build and install to /opt
I wouldn’t install python3.9 like this.
I am sticking to python 3.8
I will try from this link
https://askubuntu.com/questions/1292972/importerror-cannot-import-name-sysconfig-from-distutils-usr-lib-python3-9
and remove env and pip install virtualenv again. finally virturalenv again. it work for me. i hope help for you
Today I get so much knowledge. You always produce valuable content.
Thanks for sharing
Very helpful! Thank you!
Be careful going down this rabbit hole of the instruction in this article, you will have your fingers burnt, had to retrace my steps quickly whilst researching the quality of the article.
Whatever program you’re trying to run should probably have a distribution for python 3.8, look out for that before forcing an upgrade of your python installation, except you’re an expert in fixing broken linux boxes.