Install the latest version of Python for Linux

The new version of Python 3.11 was released yesterday. Officially, 3.11 is 10-60% faster than 3.10, and the standard test set is 1.25x faster. There are also other updates. The question is, how to update to the latest version under Linux.

1. Download the latest version of Python source code from the official website

Go to Pythonofficial website

download latest python

2. Unzip

Unzip the latest version of Python downloaded in the previous step

1tar -xvf Python-3.11.0.tar.xz

Enter the unzipped directory


3. Install dependencies

I use Ubuntu, and the corresponding dependencies for the Debian system are:

1sudo apt-get install build-essential gdb lcov pkg-config \
2     libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
3     libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
4     lzma lzma-dev tk-dev uuid-dev zlib1g-dev

Careful readers may have questions, how do you know you depend on these installation packages? In fact, the README.rst file in the decompressed Python source code directory mentions relevant dependency instructions. It is a good habit to read the documentation before installing the software. As shown in the figure below, the link contains instructions for dependent packages.

Python readme

4. Compile

There is nothing to explain in this step. If you need to adjust the configuration, you can first run ./configure --help to query the help information.


It is worth mentioning that make can accept the j parameter. For example, on a 4-core CPU system, make -j4 can speed up compilation.

5. Installation (Important Steps)

This step is critical because Python is an important software package for Linux systems. In most cases, it is not recommended to install it directly through make install. This will overwrite the basic version of Python on the system and lead to unnecessary unexpected situations. It is strongly recommended to:

1make altinstall

make altinstall will install to ${prefix}/bin/python3, and ${prefix}/bin/python3 is linked to ${prefix}/bin/python3.X, so that multiple versions can coexist harmoniously without infringing each other.

6. Confirm

If you look carefully at the output of the previous step, the latest version of Python is installed to /usr/local/bin/python3.11 by default.

1which python3.11

In order to save typing a few characters, you can make a soft link. If /usr/bin/python exists, you can back it up first and then delete it. Nowadays, most systems are upgraded to python3 by default, so choose to link to python instead of python3

1sudo ln -s /usr/local/bin/python3.11 /usr/bin/python

8. Install iPython

iPython is easier to use than Python’s own interpreter

1python -m pip install ipython

9. Final result

Checked Python and iPython, everything is fine

2Python 3.11.0 (main, Oct 25 2022, 11:03:14) [GCC 12.2.0] on linux
3Type "help", "copyright", "credits" or "license" for more information.
5➜ ~ipython
6Python 3.11.0 (main, Oct 25 2022, 11:03:14) [GCC 12.2.0]
7Type 'copyright', 'credits' or 'license' for more information
8IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.

Finally, the official Python documentation also has some relevant instructions. If you are interested, you can take a look:

Lastmod: Monday, October 16, 2023

See Also: