How to upgrade to Python 3.10 on Ubuntu 18.04 and 20.04 LTS

In this article, we will upgrade to python 3.10 and configure it as the default version of python in Ubuntu 18.04 and 20.04 LTS.

The current stable version of python was released on 06 Dec. 2021. Many ubuntu users are facing problems during upgrading python to the latest version. Python 3.9 is available as default when we install Ubuntu 20.04 LTS and Python 3.8 is available in Ubuntu 18.04. Python 3.10.0 is not available in default Ubuntu 18.04 and 20.04 repositories.

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.8.10 but yours may differ.

Install Python 3.10

Follow the simple steps to install and configure Python 3.10

Step 1: Add the repository and update

Latest Python 3.10 is 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.10

As seen in the image above, Now we have Python 3.10 available for installation.

Step 2: Install the Python 3.10 package using apt-get

install Python 3.10 by using the below command :

sudo apt-get install python3.10

Step 3: Add Python 3.8 & Python 3.10 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.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2

Step 4: Update Python 3 for point to Python 3.10

By default, Python 3 is pointed to Python 3.8. That means when we run python3 it will execute as python3.8 but we want to execute this as python3.10.

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.10. Remember the selected number may differ so choose the selection number which is for Python 3.10.

Step 5: Test the version of python

Finally, test the current version of python by typing this :

python3 -V

You should get Python 3.10 as output.

In this article, we learn how to upgrade python to the latest version that is 3.10 in Ubuntu 20.04 and 18.10.

Share your thoughts in the comment section. Happy Learning …!!

18 thoughts on “How to upgrade to Python 3.10 on Ubuntu 18.04 and 20.04 LTS”

  1. Hi,
    The instructions are nice but I’m hitting this error:

    $ sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.10 2
    update-alternatives: error: alternative path /usr/bin/python3.10 doesn’t exist

    and I don’t see Python3.10 executable here:

    $ ls -lrt /usr/bin/ | grep python
    lrwxrwxrwx 1 root root 33 Mar 13 2020 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.8-config
    lrwxrwxrwx 1 root root 16 Mar 13 2020 python3-config -> python3.8-config
    lrwxrwxrwx 1 root root 31 Mar 13 2020 py3versions -> ../share/python3/py3versions.py
    -rwxr-xr-x 1 root root 3241 Mar 15 12:22 x86_64-linux-gnu-python3.8-config
    lrwxrwxrwx 1 root root 33 Mar 15 12:22 python3.8-config -> x86_64-linux-gnu-python3.8-config
    -rwxr-xr-x 1 root root 5490448 Mar 15 12:22 python3.8
    lrwxrwxrwx 1 root root 23 Mar 15 12:22 pdb3.8 -> ../lib/python3.8/pdb.py
    lrwxrwxrwx 1 root root 25 May 10 04:37 python3 -> /etc/alternatives/python3

    So I can add it into alternatives config:

    $ sudo update-alternatives –config python3
    There is 1 choice for the alternative python3 (providing /usr/bin/python3).

    Selection Path Priority Status
    ————————————————————
    0 /usr/bin/python3.8 1 auto mode
    * 1 /usr/bin/python3.8 1 manual mode

    and status of install command:

    $ sudo apt-get install python3.10
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Note, selecting ‘libqgispython3.10.4’ for regex ‘python3.10’
    Note, selecting ‘libpython3.10-stdlib’ for regex ‘python3.10’
    libqgispython3.10.4 is already the newest version (3.10.4+dfsg-1ubuntu2).
    0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.

    $ apt list | grep python3.10

    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

    libqgispython3.10.4/focal,now 3.10.4+dfsg-1ubuntu2 amd64 [installed]

    $ python3 -V
    Python 3.8.10

    and OS is: Ubuntu 20.04.4 LTS”

    Reply
    • I was able to solve this issue by running the following steps:

      Step 1: Current state of the Python version:

      $ python3 -V
      Python 3.8.10
      $ ls /usr/bin | grep python
      python3
      python3-config
      python3.8
      python3.8-config
      x86_64-linux-gnu-python3-config
      x86_64-linux-gnu-python3.8-config
      $
      Step 2: Current state of Python alternatives:

      $ sudo update-alternatives –config python3
      There is 1 choice for the alternative python3 (providing /usr/bin/python3).

      Selection Path Priority Status
      ————————————————————
      0 /usr/bin/python3.8 1 auto mode
      * 1 /usr/bin/python3.8 1 manual mode

      Press to keep the current choice[*], or type selection number:
      $
      Step 3: Removing existing python3.10 that was attempted before:

      $ sudo apt remove python3.10
      [sudo] password for vkdevu:
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      E: Unable to locate package python3.10
      E: Couldn’t find any package by glob ‘python3.10’
      $

      $ sudo apt list | grep python3.10

      WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

      libqgispython3.10.4/focal,now 3.10.4+dfsg-1ubuntu2 amd64 [installed]
      $

      $ sudo apt remove libqgispython3.10.4
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      The following packages were automatically installed and are no longer required:
      gdal-data libaec0 libarmadillo9 libarpack2 libblas3 libcfitsio8 libcharls2 libdap25 libdapclient6v5 libdouble-conversion3
      libepsilon1 libfreexl1 libfwupdplugin1 libfyba0 libgdal26 libgeos-3.8.0 libgeos-c1v5 libgeotiff5 libgfortran5 libgif7
      libhdf4-0-alt libhdf5-103 libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libminizip1 libnetcdf15 libodbc1 libogdi4.1
      libpcre2-16-0 libpoppler97 libproj15 libqca-qt5-2 libqca-qt5-2-plugins libqgis-core3.10.4 libqhull7 libqt5concurrent5
      libqt5core5a libqt5dbus5 libqt5gui5 libqt5keychain1 libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5
      libqt5quick5 libqt5sensors5 libqt5serialport5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5webchannel5 libqt5webkit5
      libqt5widgets5 libqt5xml5 libspatialindex6 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxcb-xinerama0 libxcb-xinput0
      libxerces-c3.2 libzip5 ocl-icd-libopencl1 odbcinst odbcinst1debian2 poppler-data proj-bin proj-data qt5-gtk-platformtheme
      qttranslations5-l10n
      Use ‘sudo apt autoremove’ to remove them.
      The following packages will be REMOVED:
      libqgispython3.10.4
      0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
      After this operation, 2379 kB disk space will be freed.
      Do you want to continue? [Y/n] Y
      (Reading database … 130630 files and directories currently installed.)
      Removing libqgispython3.10.4 (3.10.4+dfsg-1ubuntu2) …
      Processing triggers for libc-bin (2.31-0ubuntu9.9) …
      $
      Step 4: Ensure that your system is updated and the required packages installed:

      $ sudo apt update && sudo apt upgrade -y
      Ign:1 https://pkg.jenkins.io/debian binary/ InRelease
      Hit:2 https://pkg.jenkins.io/debian binary/ Release
      Get:3 http://mirrors.digitalocean.com/ubuntu focal InRelease [265 kB]
      Get:5 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease [114 kB]
      Get:6 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease [108 kB]
      Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
      Get:8 http://mirrors.digitalocean.com/ubuntu focal-updates/main amd64 Packages [1789 kB]
      Get:9 http://mirrors.digitalocean.com/ubuntu focal-updates/universe amd64 Packages [921 kB]
      Fetched 3310 kB in 2s (1657 kB/s)
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      All packages are up to date.
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Calculating upgrade… Done
      The following packages were automatically installed and are no longer required:
      gdal-data libaec0 libarmadillo9 libarpack2 libblas3 libcfitsio8 libcharls2 libdap25 libdapclient6v5 libdouble-conversion3
      libepsilon1 libfreexl1 libfwupdplugin1 libfyba0 libgdal26 libgeos-3.8.0 libgeos-c1v5 libgeotiff5 libgfortran5 libgif7
      libhdf4-0-alt libhdf5-103 libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libminizip1 libnetcdf15 libodbc1 libogdi4.1
      libpcre2-16-0 libpoppler97 libproj15 libqca-qt5-2 libqca-qt5-2-plugins libqgis-core3.10.4 libqhull7 libqt5concurrent5
      libqt5core5a libqt5dbus5 libqt5gui5 libqt5keychain1 libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5
      libqt5quick5 libqt5sensors5 libqt5serialport5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5webchannel5 libqt5webkit5
      libqt5widgets5 libqt5xml5 libspatialindex6 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxcb-xinerama0 libxcb-xinput0
      libxerces-c3.2 libzip5 ocl-icd-libopencl1 odbcinst odbcinst1debian2 poppler-data proj-bin proj-data qt5-gtk-platformtheme
      qttranslations5-l10n
      Use ‘sudo apt autoremove’ to remove them.
      0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
      $
      Step 5: Install Python 3.10 on Ubuntu 20.04|18.04 using Apt Repo:

      $ sudo apt install software-properties-common -y
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      software-properties-common is already the newest version (0.99.9.8).
      software-properties-common set to manually installed.
      The following packages were automatically installed and are no longer required:
      gdal-data libaec0 libarmadillo9 libarpack2 libblas3 libcfitsio8 libcharls2 libdap25 libdapclient6v5 libdouble-conversion3
      libepsilon1 libfreexl1 libfwupdplugin1 libfyba0 libgdal26 libgeos-3.8.0 libgeos-c1v5 libgeotiff5 libgfortran5 libgif7
      libhdf4-0-alt libhdf5-103 libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libminizip1 libnetcdf15 libodbc1 libogdi4.1
      libpcre2-16-0 libpoppler97 libproj15 libqca-qt5-2 libqca-qt5-2-plugins libqgis-core3.10.4 libqhull7 libqt5concurrent5
      libqt5core5a libqt5dbus5 libqt5gui5 libqt5keychain1 libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5
      libqt5quick5 libqt5sensors5 libqt5serialport5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5webchannel5 libqt5webkit5
      libqt5widgets5 libqt5xml5 libspatialindex6 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxcb-xinerama0 libxcb-xinput0
      libxerces-c3.2 libzip5 ocl-icd-libopencl1 odbcinst odbcinst1debian2 poppler-data proj-bin proj-data qt5-gtk-platformtheme
      qttranslations5-l10n
      Use ‘sudo apt autoremove’ to remove them.
      0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
      $
      Step 6: Then proceed and add the deadsnakes PPA to the APT package manager sources list:

      $ sudo add-apt-repository ppa:deadsnakes/ppa
      This PPA contains more recent Python versions packaged for Ubuntu.

      Disclaimer: there’s no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

      Update Note
      ===========
      Please use this repository instead of ppa:fkrull/deadsnakes.

      Reporting Issues
      ================

      Issues can be reported in the master issue tracker at:
      https://github.com/deadsnakes/issues/issues

      Supported Ubuntu and Python Versions
      ====================================

      – Ubuntu 18.04 (bionic) Python2.3 – Python 2.6, Python 3.1 – Python 3.5, Python3.7 – Python3.11
      – Ubuntu 20.04 (focal) Python3.5 – Python3.7, Python3.9 – Python3.11
      – Ubuntu 22.04 (jammy) Python3.7 – Python3.9, Python3.11
      – Note: Python2.7 (all), Python 3.6 (bionic), Python 3.8 (focal), Python 3.10 (jammy) are not provided by deadsnakes as upstream ubuntu provides those packages.

      Why some packages aren’t built:
      – Note: for focal, older python versions require libssl<1.1 so they are not currently built
      – Note: for jammy, older python versions requre libssl x86_64-linux-gnu-python3.8-config
      lrwxrwxrwx 1 root root 16 Mar 13 2020 python3-config -> python3.8-config
      lrwxrwxrwx 1 root root 31 Mar 13 2020 py3versions -> ../share/python3/py3versions.py
      -rwxr-xr-x 1 root root 3241 Mar 15 12:22 x86_64-linux-gnu-python3.8-config
      lrwxrwxrwx 1 root root 33 Mar 15 12:22 python3.8-config -> x86_64-linux-gnu-python3.8-config
      -rwxr-xr-x 1 root root 5490448 Mar 15 12:22 python3.8
      lrwxrwxrwx 1 root root 23 Mar 15 12:22 pdb3.8 -> ../lib/python3.8/pdb.py
      -rwxr-xr-x 1 root root 5789976 Apr 8 17:35 python3.10
      lrwxrwxrwx 1 root root 24 Apr 8 17:35 pdb3.10 -> ../lib/python3.10/pdb.py
      lrwxrwxrwx 1 root root 25 May 10 04:37 python3 -> /etc/alternatives/python3
      $

      $ sudo update-alternatives –config python3
      There is 1 choice for the alternative python3 (providing /usr/bin/python3).

      Selection Path Priority Status
      ————————————————————
      0 /usr/bin/python3.8 1 auto mode
      * 1 /usr/bin/python3.8 1 manual mode

      Press to keep the current choice[*], or type selection number:
      $

      Reply
      • —–> continuation for my previous post —->

        Step 7: Download Python 3.10 with the single command below:

        $ sudo apt install python3.10
        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        The following packages were automatically installed and are no longer required:
        gdal-data libaec0 libarmadillo9 libarpack2 libblas3 libcfitsio8 libcharls2 libdap25 libdapclient6v5 libdouble-conversion3
        libepsilon1 libfreexl1 libfwupdplugin1 libfyba0 libgdal26 libgeos-3.8.0 libgeos-c1v5 libgeotiff5 libgfortran5 libgif7
        libhdf4-0-alt libhdf5-103 libkmlbase1 libkmldom1 libkmlengine1 liblapack3 libminizip1 libnetcdf15 libodbc1 libogdi4.1
        libpcre2-16-0 libpoppler97 libproj15 libqca-qt5-2 libqca-qt5-2-plugins libqgis-core3.10.4 libqhull7 libqt5concurrent5
        libqt5core5a libqt5dbus5 libqt5gui5 libqt5keychain1 libqt5network5 libqt5positioning5 libqt5printsupport5 libqt5qml5
        libqt5quick5 libqt5sensors5 libqt5serialport5 libqt5sql5 libqt5sql5-sqlite libqt5svg5 libqt5webchannel5 libqt5webkit5
        libqt5widgets5 libqt5xml5 libspatialindex6 libspatialite7 libsuperlu5 libsz2 liburiparser1 libxcb-xinerama0 libxcb-xinput0
        libxerces-c3.2 libzip5 ocl-icd-libopencl1 odbcinst odbcinst1debian2 poppler-data proj-bin proj-data qt5-gtk-platformtheme
        qttranslations5-l10n
        Use ‘sudo apt autoremove’ to remove them.
        The following additional packages will be installed:
        libpython3.10-minimal libpython3.10-stdlib python3.10-minimal
        Suggested packages:
        python3.10-venv binfmt-support
        The following NEW packages will be installed:
        libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal
        0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
        Need to get 5171 kB of archives.
        After this operation, 20.0 MB of additional disk space will be used.
        Do you want to continue? [Y/n] Y
        Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-minimal amd64 3.10.4-1 focal2 [820 kB]
        Get:2 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10-minimal amd64 3.10.4-1 focal2 [2073 kB]
        Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 libpython3.10-stdlib amd64 3.10.4-1 focal2 [1746 kB]
        Get:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 python3.10 amd64 3.10.4-1 focal2 [532 kB]
        Fetched 5171 kB in 5s (1098 kB/s)
        Selecting previously unselected package libpython3.10-minimal:amd64.
        (Reading database … 130626 files and directories currently installed.)
        Preparing to unpack …/libpython3.10-minimal_3.10.4-1 focal2_amd64.deb …
        Unpacking libpython3.10-minimal:amd64 (3.10.4-1 focal2) …
        Selecting previously unselected package python3.10-minimal.
        Preparing to unpack …/python3.10-minimal_3.10.4-1 focal2_amd64.deb …
        Unpacking python3.10-minimal (3.10.4-1 focal2) …
        Selecting previously unselected package libpython3.10-stdlib:amd64.
        Preparing to unpack …/libpython3.10-stdlib_3.10.4-1 focal2_amd64.deb …
        Unpacking libpython3.10-stdlib:amd64 (3.10.4-1 focal2) …
        Selecting previously unselected package python3.10.
        Preparing to unpack …/python3.10_3.10.4-1 focal2_amd64.deb …
        Unpacking python3.10 (3.10.4-1 focal2) …
        Setting up libpython3.10-minimal:amd64 (3.10.4-1 focal2) …
        Setting up python3.10-minimal (3.10.4-1 focal2) …
        Setting up libpython3.10-stdlib:amd64 (3.10.4-1 focal2) …
        Setting up python3.10 (3.10.4-1 focal2) …
        Processing triggers for man-db (2.9.1-1) …
        Processing triggers for desktop-file-utils (0.24-1ubuntu3) …
        Processing triggers for mime-support (3.64ubuntu1) …
        Processing triggers for gnome-menus (3.36.0-1ubuntu1) …
        $
        Step 8: Verify the installation by checking the installed version:

        $ python3.10 –version
        Python 3.10.4
        $
        Step 9: Add Python 3.10.4 to alternatives config:

        $ ls -lrt /usr/bin/ | grep python
        lrwxrwxrwx 1 root root 33 Mar 13 2020 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.8-config
        lrwxrwxrwx 1 root root 16 Mar 13 2020 python3-config -> python3.8-config
        lrwxrwxrwx 1 root root 31 Mar 13 2020 py3versions -> ../share/python3/py3versions.py
        -rwxr-xr-x 1 root root 3241 Mar 15 12:22 x86_64-linux-gnu-python3.8-config
        lrwxrwxrwx 1 root root 33 Mar 15 12:22 python3.8-config -> x86_64-linux-gnu-python3.8-config
        -rwxr-xr-x 1 root root 5490448 Mar 15 12:22 python3.8
        lrwxrwxrwx 1 root root 23 Mar 15 12:22 pdb3.8 -> ../lib/python3.8/pdb.py
        -rwxr-xr-x 1 root root 5789976 Apr 8 17:35 python3.10
        lrwxrwxrwx 1 root root 24 Apr 8 17:35 pdb3.10 -> ../lib/python3.10/pdb.py
        lrwxrwxrwx 1 root root 25 May 10 04:37 python3 -> /etc/alternatives/python3
        $

        $ sudo update-alternatives –config python3
        There is 1 choice for the alternative python3 (providing /usr/bin/python3).

        Selection Path Priority Status
        ————————————————————
        0 /usr/bin/python3.8 1 auto mode
        * 1 /usr/bin/python3.8 1 manual mode

        Press to keep the current choice[*], or type selection number:
        $

        $ python3 -V
        Python 3.8.10
        $ python -V

        Command ‘python’ not found, did you mean:

        command ‘python3’ from deb python3
        command ‘python’ from deb python-is-python3

        $

        $ sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.8 1
        $ sudo update-alternatives –install /usr/bin/python3 python3 /usr/bin/python3.10 2
        $
        $ sudo update-alternatives –config python3
        There are 2 choices for the alternative python3 (providing /usr/bin/python3).

        Selection Path Priority Status
        ————————————————————
        0 /usr/bin/python3.10 2 auto mode
        1 /usr/bin/python3.10 2 manual mode
        * 2 /usr/bin/python3.8 1 manual mode

        Press to keep the current choice[*], or type selection number: 0
        update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode
        $
        $
        $ python3 -V
        Python 3.10.4
        $ sudo update-alternatives –config python3
        There are 2 choices for the alternative python3 (providing /usr/bin/python3).

        Selection Path Priority Status
        ————————————————————
        * 0 /usr/bin/python3.10 2 auto mode
        1 /usr/bin/python3.10 2 manual mode
        2 /usr/bin/python3.8 1 manual mode

        Press to keep the current choice[*], or type selection number:
        $

        Reply

Leave a Comment