How to Install Latest Python from Source in Linux

Several top universities around the globe use Python to introduce students to programming. The Massachusetts Institute of Technology (MIT), the University of Texas at Arlington, and Stanford are only a few examples of institutions that use this language extensively.

Additionally, it is important to note that Python is also useful for a wide variety of educational, enterprise, and scientific purposes – from web development to desktop applications to machine learning and everything in between.

Currently, there are two major Python versions in use – 2 and 3, with 2 rapidly losing ground to 3 since the former is no longer under active development. Since all Linux distributions come with Python 2.x installed.

In this article, we will show how to install and use the latest Python version in RHEL-based distributions and Debian and its derivatives such as Ubuntu (the latest LTS version already has the latest Python installed) or Linux Mint. Our focus will be installing the core language tools that can be used in the command line.

However, we will also explain how to install Python IDLE – a GUI-based tool that allows us to run Python code and create standalone functions.

Install Python on Linux from Source

At the time of this writing (November 2022), the latest version is Python 3.11, and we are going to perform the installation from the source.

Although we can install the core packages and their dependencies using yum and aptitude (or apt-get) or apt.

Why? The reason is simple: this allows us to have the latest stable release of the language (3.11) and to provide a distribution-agnostic installation method.

Prior to installing Python in RHEL-based distributions such as CentOS Stream Fedora, Rocky, and AlmaLinux, let’s make sure our system has all the necessary development dependencies:

# yum -y groupinstall development
# yum -y install zlib-devel

In >Debian-based distributions such as Ubuntu and Linux Mint, we will need to install gcc, make, and the zlib compression/decompression library:

# aptitude -y install gcc make zlib1g-dev

Once needed core packages are installed, you can head over to the official Python download page to download the Python 3.11 source release or use the following wget command to download it directly and install it.

# wget
# tar xJf Python-3.11.0.tar.xz
# cd Python-3.11.0
# ./configure
# make
# make install
Install Python on Linux
Install Python on Linux

Now relax and go grab a sandwich because this may take a while. When the installation is complete, use which to verify the location of the main binary:

# which python3
# python3 -V
# python3

The output of the above command should be similar to:

[root@tecmint:~/Python-3.11.0]# which python3
[root@tecmint:~/Python-3.11.0]# python3 -V
Python 3.11.0
[root@tecmint:~/Python-3.11.0]# python3
Python 3.11.0 (main, Nov 15 2022, 09:50:56) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> quit()

Congratulations! Python 3.11 is now installed on your system.

Install Python IDLE on Linux

Python IDLE is a GUI-based tool for Python. If you wish to install the Python IDLE, grab the package named idle (Debian) or python-tools (RHEL).

# yum install python3-idle  [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
# apt-get install idle       [On Debian, Ubuntu and Mint]

Type the following command to start the Python IDLE.

# idle3
# idle
Python IDLE Editor
Python IDLE Editor

In this article, we have explained how to install the latest Python stable version from the source.

Last, but not least, if you’re coming from Python 2, you may want to take a look at the 2to3 official documentation. This is a program that reads Python 2 code and transforms it into valid Python 3 code.

Do you have any questions or comments about this article? Feel free to get in touch with us using the form below.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

15 thoughts on “How to Install Latest Python from Source in Linux”

  1. Installing from source as *root* is usually a bad idea. There is no uninstall step. You are likely to overwrite packages maintained by your system package manager (yum, apt, etc.) On Red Hat you can break yum which is difficult to recover from.

    Install packages if they are available. There are several choices of Python 3 packages for most distributions.

    Only build from source if you have to for some reason and then install someplace other than /usr.


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.