How Do You Upgrade Python 2.x to Python 3.7 in Debian or Ubuntu Linux?

Problem scenario
You have a virtual server running Ubuntu 18.x in Azure. It has Python 2.x. How do you upgrade to Python 3.x?

Solution
1. Run these two commands:
sudo apt -y update
sudo apt -y install python 3.7

2. Find where the binary python3.7 is by running this: sudo find / -name python3.7
Make a mental note of the result. It should be something like /usr/bin/python3.7

3. Run this: which python

4. Back up the resulting file (e.g., sudo mv /usr/bin/python /usr/bin/bakpythonbak)

5. Draft a command like this, but substitute /usr/bin/python3.7 with the path found in step #2.

sudo ln -s /usr/bin/python3.7 /usr/bin/python

6. Run the command above from step #5.

7. Test it. Run this: python --version
Once Python is working to your satisfaction, you may want to delete /usr/bin/bakpythonbak.

You should now be done. If you want to upgrade Python on any distribution of Linux without using binaries (e.g., using source media), see this posting as a guide.

Leave a comment

Your email address will not be published. Required fields are marked *