175

I want to install Python 3.9 on my Ubuntu 20.04, and all tutorials I can find include a step as follows:

sudo add-apt-repository ppa:deadsnakes/ppa

I am concerned about security. I've looked into this question: Are PPAs safe to add to my system and what are some "red flags" to watch out for?

According to the answers, some of the main points to consider are:

Attempts to search the internet for deadsnakes only brought me into tutorials on how to install Python, which is where I started...

BenMorel
  • 173
Pedro A
  • 1,963

2 Answers2

109

Note: Please don't change the default version of python3. You may end up destroying Ubuntu. Instead, run python3.9 with the command python3.9.

Also, you can install python 3.9.5 in Ubuntu 20.04 even without the deadsnake PPA with the commands

sudo add-apt-repository universe
sudo apt update
sudo apt install python3.9

For other versions of Ubuntu (e.g. 22.04), you may need the deadsnakes ppa.

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9

If you want to install a later version, e.g. python3.12, run the following commands

sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.12

Now let's answer your questions.

Someone named deadsnakes

No, deadsnakes is a pun on python.

Who made the PPA

As you can see here, the packages in the PPA are uploaded by Felix Krull, Anthony Sottile, Ɓukasz Langa. The development happens over GitHub

How many users have used the PPA

According to PPA Stats, Python3.9 alone has been downloaded 2208666 times, as of writing this answer. On average, there are 10000 downloads per day.

1

Installing the latest version of Python on Ubuntu, directly from source code from python.org

Tested on Ubuntu 20.04.

This is how to install/upgrade/update the latest version of Python on any version of Ubuntu, or even Linux for that matter.

  1. First, try installing the latest version that comes with your Ubuntu distribution:

    sudo apt update
    sudo apt install python3
    

    check version

    python3 --version # shows 3.8 on Ubuntu 20.04

  2. If that version isn't new enough (ex: the zoneinfo module wasn't added until Python 3.9), then you can install from source.

    Download the latest version here: https://www.python.org/downloads/. This will be just the source code.

    In your file manager, right-click and extract it (it will be a .tar.gz zip file), cd into it, and run the following to build and install it:

    time ./configure --enable-optimizations
    time make -j "$(nproc)"  # takes < 5 minutes w/8 cores
    time make test  # takes < 3 minutes
    sudo make install
    

    CLOSE AND RE-OPEN THE TERMINAL NOW TO GET THE NEW PYTHON VERSION to

    show up, OR re-source your ~/.bashrc file for each open terminal

    . ~/.bashrc

    Check the version; should now be >= 3.13.2 at the time

    of this writing

    python3 --version

    Upgrade pip

    pip3 install --upgrade pip

    (Won't apply to most people)

    If you have a requirements.txt file in yoru project directory,

    re-install all required modules now at this time, using that file

    pip3 install -r requirements.txt --upgrade

The end.

Gabriel Staples
  • 11,502
  • 14
  • 97
  • 142