How to Compile & Install Python 3.10.0 from Source in Ubuntu 21.04, 21.10

Last updated: April 25, 2022 — 9 Comments

This simple tutorial shows how to compile and install Python 3.10.0 or other certain Python version in Ubuntu.

For Ubuntu 18.04 and Ubuntu 20.04 LTS, there’s well trusted “deadsnakes” team PPA that maintains all the Python packages. For non-LTS releases, e.g., Ubuntu 21.04 and Ubuntu 21.10, you may build the programming language package manually from the source tarball.

NOTE: Ubuntu 21.04 has Python 3.10 beta1 in universe repository, remove it if installed before doing the steps below. For Ubuntu 21.10, Python 3.10 will be soon made into the universe repository, so you may skip or install a certain version (e.g., 3.8 or 3.7) via this tutorial.

1. Preparation:

Before getting started, you need to install some essential packages for building the computer language package.

Open terminal either by pressing Ctrl+Alt+T on keyboard or by searching from start menu. When it opens, run the command below to install the dependencies:

sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

2. Download Python Tarball:

Next, download the source package by running the wget command in terminal:

wget -c

For other Python version, go and download via web browser in this page.

And uncompress the tarball either by right-click and selecting ‘Extract Here‘ in file manager, or by running command in terminal:

tar -Jxf Python-3.10.0.tar.xz

3. Configure the source:

After extracted the source, go to new generated folder via command:

cd Python-3.10.0/

The command varies depends on which Python version you downloaded. You may right-click on the folder and choose ‘Open in Terminal‘ instead of running cd command.

When you’re in source directory, run command to configure the source with expensive, stable optimizations (PGO, etc.):

./configure --enable-optimizations

4. Build and install Python:

Finally compile and install it into “/usr/local/bin”:

sudo make altinstall -j4

Here -j4 will start 4 threads to speed up the job. Depends on your CPU, you may increase the number or just skip it.

5. Make Python 3.10 default

After installation, verify via python3.10 -V command. You may set it as default by creating symbolic links to /usr/bin/python:

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1

It’s possible to set Python3.10 as Python3. However, this may cause issues since it points to system default python that is required for some core apps.

Uninstall Python 3.10:

Until you removed the source directory, you may run command to navigate to that folder and do make uninstall to remove Python 3.10:

cd Python-3.10.0 && sudo make uninstall

If you’ve already removed the source, either re-run step 1, 2 & 3 and use the command above to uninstall, or manually remove all installed files via command:

Don’t paste and run the command below in Ubuntu 22.04. It will remove the default Python 3.10 that will break your system!

sudo rm -R /usr/local/bin/python3.10 /etc/python3.10 /usr/local/lib/python3.10


I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee:

9 responses to How to Compile & Install Python 3.10.0 from Source in Ubuntu 21.04, 21.10

  1. Awsome!
    To the point with no extras.
    Thank you,

  2. Jerry Yang(Korea) October 17, 2021 at 7:17 am

    Thanks. perfect~!!

  3. Hey, so I’ve installed python but can’t seem to figure out how to launch the app.
    Any help would be appreciated!

  4. Perfect tutorial!! Keep up the great work!!

  5. how to uninstall?

  6. A Random Try Hard Linux User December 9, 2021 at 5:22 am

    If I use the second method in uninstalling Python 3.10.0, that’s it, right?

  7. Thanks for the steps. It really helped

  8. I used this instruction to install Python 3.10.4 (of course, I had to replace .0 with .4) and it worked great. Thank you!

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 


This site uses Akismet to reduce spam. Learn how your comment data is processed.