Installing Python 3 on CentOS 8
Traducciones al EspañolEstamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Python is a popular programming language created in 2000, by Guido van Rossum. It’s useful for writing everything from small scripts to full-scale software. Python is also a commonly adopted programming language by people entering into the field of software development. A lot of its popularity is based on Python’s high level of abstraction. This abstraction makes writing and reading the code easier than other languages.
As of January 1, 2020, the official version of Python is Python 3. Python 2 is no longer a supported language. This guide walks you through installing the latest version of Python 3 on Debian 10. If you are interested in porting your already existing Python 2 code to Python 3, please refer to the official documentation on how to do so.
Unlike other Linux distributions, CentOS 8 does not come with a version of Python installed. Currently Python 3.9 is the latest major version of Python. This guide shows two options for installing Python 3 on CentOS 8:
How to install Python 3.6 from the CentOS package repository. Python 3.6 is the most recent version of Python in the CentOS package repository is Python 3.6.
This guide assumes that you have access to a server or workstation running CentOS 8. To provision a Linode running CentOS 8, follow our Getting Started guide.
This guide uses
sudowherever possible. Complete the sections of our Setting Up and Securing a Compute Instance to create a standard user account, harden SSH access, and remove unnecessary network services.
Update your system:
sudo yum update
You need to build Python 3.9 from source to install it on CentOS 8.
Download the dependencies to build the package:
sudo dnf groupinstall 'development tools' sudo dnf install wget openssl-devel bzip2-devel libffi-devel
Download Python version 3.9:
sudo curl https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz -O
Extract the Python package:
tar -xvf Python-3.9.1.tgz
Change into the Python directory:
Run the configuration script and run the build process:
sudo ./configure --enable-optimizations sudo make installIf you have an already existing Python binary installed at
/usr/bin/python3, you should run
sudo make altinstallinstead.
After the installation is finished, you can run the command
python3 -Vand verify the installation:
The output looks like this:
If you do not need the latest version of Python, you can install Python 3.6 using the CentOS repository. This version is included in the CentOS repository by default. While this installation method is easier than the previous from source method, it is not the latest version. Install version 3.6 by running the following command:
sudo dnf install python3
If you haven’t installed any other version of Python, you can verify this installation by typing:
And the shell returns:
If you installed Python 3.9 by compiling from source, the installed binary is located at
/usr/local/bin/python3. If you installed Python 3.8 from the CentOS package repository, the installed binary is located at
You may require Python 2 as a dependency for older code or software. If this is the case, you can install it with the following command:
sudo dnf install python2
python2 -V to check the version:
The output looks like the following:
It’s important to remember that Python2 is no longer supported by the Python foundation. Therefore, there are no new updates or fixes. Applications are making the switch to Python 3, and distributions like Ubuntu 20.04 and CentOS 8 are no longer shipping with Python 2 by default.
This page was originally published on