Python is a powerful and widely-used programming language, known for its simplicity, readability, and versatility across various domains such as web development, data science, and machine learning. With the release of Python 3.9, developers can benefit from numerous enhancements, optimizations, and new features.
In this tutorial, we will guide you through the process of installing Python 3.9 on CentOS/RHEL 8 operating systems using the source archive file. This approach to installation provides greater control and customization, ensuring that you have the latest version of Python installed on your system.
Prerequisites
This Python installation required the GCC compiler on your system. Login to your server using ssh or shell access. 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 1 – Download Python 3.9
Visit the official download site https://www.python.org/ftp/python to download the latest or required version of the Python.
Command line users can download Python 3.9 via command line:
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
Then, extract the archive file on your system
tar xzf Python-3.9.16.tgz
This will create a directory named Python-3.9.16 in the current directory containing all source files for Python 3.9.
Step 2 – Install Python on CentOS 8
Change directory to Python-3.9.6. Then prepare the source code with the required values before compiling it.
cd Python-3.9.16
sudo ./configure --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions
Next, compile the source code with make. Here nproc
will provide the number of CPU cores available on system. So that make can perform well.
sudo make -j ${nproc}
sudo make altinstall
Now, we don’t need the downloaded archive file, so delete it to free space.
sudo rm Python-3.9.16.tgz
Step 3 – Test Python Version
At this step, you have successfully installed Python 3.9 on CentOS/RHEL system. Now, check the installed versions of Python and PIP.
Check Python Version:
python3.9 -V
Python 3.9.16
Check PIP Version:
pip3.9 -V
pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
Step 4 – Create Virtual Environment
It is a good idea to create a separate virtual environment for each Python application. Which provides an isolated environment where the Python project has its own modules and set of dependencies.
To create Python virtual environment, run:
sudo /usr/local/bin/python3.9 -m venv /home/rahul/python-app/venv
All the files will be generated under /home/rahul/python-app/venv directory. You can active the environment by running command:
source /home/rahul/python-app/venv/bin/activate
Do your stuff with isolated environment here. Once you finish with your work, deactivate the environment by typing:
deactivate
This will return you back to the main system prompt.
Conclusion
We have successfully demonstrated the step-by-step procedure to install Python 3.9 on CentOS/RHEL 8 systems using the source archive file. This method offers a tailored installation experience, enabling you to make the most of Python 3.9’s performance improvements and new features. As you delve deeper into the Python ecosystem, take the time to explore the vast array of libraries and frameworks available, which will further enhance your programming skills and streamline your projects. With Python 3.9 installed on your CentOS/RHEL 8 system, you are now well-equipped to tackle a diverse range of programming challenges and build cutting-edge applications.
3 Comments
Hi, Can you create steps on how to uninstall it too?
This was helpful though. Thanks!
Thank you!
It works like a charm!
Great job on the tutorial!!! Your site seems to be one of the best sites for “How-To” information on Red Hat/Centos.