25

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?

Kulfy
  • 18,154

3 Answers3

36

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.

1

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

Aditya
  • 31
  • 3
0

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.

https://packages.ubuntu.com/search?keywords=python3.9&searchon=names&suite=all&section=all