I want to install Python 3.9 in Ubuntu. When I run sudo apt-get python in the terminal it says that it will install Python 2 which I don't want. When I type sudo apt-get install python3.9 it shows that it is an invalid operation.

How do I install Python 3.9?


3 Answers 3


As you're "new to Linux", I won't suggest compiling from source. Instead, there is a PPA that you'll need to add to apt so that you can use 3.9. Here are the steps:

  1. Open Terminal (if it's not already open)
  2. Update apt and confirm that you have the prerequisites installed:
    sudo apt update
    sudo apt install software-properties-common
  3. The PPA you'll need to add is maintained by "deadsnakes", so let's add that:
    sudo add-apt-repository ppa:deadsnakes/ppa
    You'll be asked if you want to continue. Press Enter to do so.
  4. Update apt again:
    sudo apt update
  5. Install Python 3.9:
    sudo apt install python3.9
  6. Confirm that the installation was successful:
    python3.9 --version 
    You should see:
    Python 3.9.1+

That's all there is to it. When you use anything that specifically requires Python 3.9, be sure to use python3.9 as the command, not python or python3.

Warning: Do not remove the default version of Python(3.x) which was preinstalled in Ubuntu, even if you install Python 3.9. Removing the default python version may break your system.

  • What a joke lmao. 'deadsnakes' , are you kidding me? Very professional stuff going on there
    – Anthony
    Aug 15, 2021 at 18:44
  • 3
    @Anthony I don't see a problem with the name -- deadsnakes is a repository of old python versions, so, the name fits
    – Jack
    Aug 18, 2021 at 0:20
  • I did remove, by mistake, the default version (3.5), because of one of the answers out there told to do so. How do I fix that "broken stuff"?
    – Nathan B
    Mar 22 at 11:13
  • I ran all of these commands. The "install" of python3.9 was over in less than 1 second and says "The following packages were automatically installed and are no longer required" with a huge list. When I run python3.9 --version it returns python3.9 command not found. python3 --version returns Python 3.5.2. Now what? Jun 11 at 12:06
  • It looks like Ubuntu 16.04 is no longer supported by the deadsnakes respository Jun 17 at 17:07

Install synaptic using

sudo apt update
sudo apt-get install synaptic

Then, open synaptic and click on search button. Type "Python 3.9" and press Enter. Now click on the box next to python3.9 and click on mark for installation. On top click on Apply button.

see image


You need to be running at least 20.04 with the focal-updates repository enabled. Looking at the output of the command apt-cache policy python3.9 will tell you if available when used in the Terminal program. Using apt install python3.9 if it is available can possible install it for you if the dependencies are right.


Not the answer you're looking for? Browse other questions tagged or ask your own question.