Python is the popular high-level programming language, which is universal, fast and used in many projects, including large ones.
Installing the fresh variant of the libraries for supporting Python language in CentOS operating system is not difficult, especially if you follow everything in stages. In this tutorial, we will build version 3.10.11 from sources.
Updating Operating System Packages
Before updating Python directly, we update the operating system. Navigate terminal then execute:
sudo dnf update
sudo dnf upgrade
Installing Python on CentOS
To work with Python you need to install it on your computer, which can be a non-trivial task for Linux newbies. At this point, we'll walk via the installation step by step and provide detailed tutorial with commands and descriptions of each step.
Installing additional packages
If your system does not have the "wget" module, execute the commands one after the other:
sudo yum search wget
sudo yum install wget
For further work, you need to get packages:
yum install gcc yum-utils zlib-devel python-tools cmake git pkgconfig -y --skip-broken
After successfully completing the installation, let's install the "Development Tools"
yum groupinstall -y "Development Tools" --skip-broken
To continue, you must go to the directory:
cd /usr/src
Loading source files
We get the latest version from the Python.org website. Visiting it, under "Downloads\Source code" copy the download link we found and need. Then run in the terminal, pasting in the just copied link:
wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
After downloading, you must retrieve the contents of the archive. You can use this command to do so:
tar xzf Python-3.11.3.tgz
Navigate to the resulting Python-3.11.3 folder and install directly from the source code:
./configure
Complete the installation by executing the commands one after the other:
make
make install
Make sure the update is successful by sending a line to the terminal:
python3 --version
If version 3.11.x of Python is displayed, then all previous steps have gone correctly! It is now possible to use the universal programming language for your own purposes.
Python version update
If you already have an earlier version of Python, follow the steps below.
Installing additional Python packages
In order to perform a Python version upgrade, a few new packages must be supplied in addition. Send commands to the terminal:
yum groupinstall -y "Development Tools" --skip-broken
wget https://public-yum.oracle.com/public-yum-ol6.repo -O /etc/yum.repos.d/public-yum-ol6.repo
dnf --enablerepo=powertools install libpcap-devel
sudo dnf install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
Loading source files
We get the latest version from the Python.org website. Visiting it, under "Downloads\Source code" copy the download link we found and need. Then run in the terminal, pasting in the just copied link:
wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
After downloading, you must retrieve the contents of the archive. You can use this command to do so:
tar xzf Python-3.11.3.tgz
Update version
Navigate to the resulting Python-3.11.3 folder and install directly from the source code:
./configure --enable-optimizations
make
make install
Check update
Make sure the update is successful by running the command:
python3 --version
If Python version 3.11.x is displayed then the update was successful.
Summary
In this review, we looked at "How to update Python on CentOS" by using source code files.