How to Install Python 3.9 on CentOS 8

Install Python 3.9 on CentOS 8

In this article, we will have explained the necessary steps to installing and configure Python 3.9 on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Python is a free, open-source, and the most popular programming language around the world. It is a versatile language and used to construct all kinds of applications. It’s the best choice for beginners due to its simple and easy-to-learn syntax. The Python 3.9 version is the most up-to-date released with various innovations and safety updates.

Install Python 3.9 on CentOS 8

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf install epel-release
sudo dnf update

Step 2. Install Python Dependencies.

Now, use the following command to install prerequisites for Python before installing it:

sudo dnf install wget yum-utils make gcc openssl-devel bzip2-devel libffi-devel zlib-devel

Step 3. Download the latest Python 3.9 Archive.

Download the latest release source code from the Python download page using wget a command:

tar xvf Python-3.9.1.tgz
cd Python-3.9.1

Step 4. Install Python 3.9 on the CentOS system.

Run the command below to configure Python installation:

sudo ./configure --enable-optimizations

Initiate compilation of Python 3.9 on CentOS 8:

sudo make altinstall

At this step, you have successfully installed Python 3.9 on CentOS/RHEL system. Now, check the installed versions of Python and PIP:

python3.9 --version

Step 4. Create Virtual Environment.

To create Python virtual environment, run:

sudo /usr/local/bin/python3.9 -m venv /home/rahul/python-app/venv

Next, you can activate the environment by running the command:

source /home/rahul/python-app/venv/bin/activate

That’s all you need to do to install Python on CentOS 8. I hope you find this quick tip helpful. For further reading on Python 3.9, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.