Step-by-Step Guide to Installing Python 3.9 on Rocky Linux 8

Python is a versatile programming language used for creating a multitude of applications, from full-scale games and web applications to simple scripts for your PC or Mac. Since its inception in the late 1980s, Python remains one of the most popular and widely-used languages today.

This tutorial will guide you on installing Python 3.9 on a Rocky Linux 8 system.

Prerequisites

  • A Rocky Linux 8 system. Any relatively recent version of Rocky Linux should be compatible with these instructions.
  • A non-root user with sudo privileges configured on your Rocky system.

Updating the System

To ensure that your system software packages are up-to-date with the latest stable versions, execute the following command before starting the Python installation:

sudo dnf -y update

Install Python 3.9 Using the Official Repository

The default Rocky Linux 8 AppStream repository currently includes Python versions 3.7, 3.8, and 3.9. To install the latest version, run:

sudo dnf install python39

Press Y and hit Enter when prompted to begin the installation.

install python39

After the installation completes, verify the version with:

python3.9 --version

python3.9 --version

Python 3.9 should now be installed and ready for use on your Rocky system.

Installing Python 3.9 Manually

If you cannot access the AppStream repository or prefer an alternative installation method, you can manually install Python 3.9 using the Python archive. Begin by installing the necessary packages for compiling Python:

sudo dnf groupinstall "Development Tools" -y

Next, install required dependencies like openssl-devel and libffi-devel:

sudo dnf install openssl-devel libffi-devel bzip2-devel -y

Download the latest Python version and extract it:

sudo dnf install wget -y
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tar.xz
tar xvf Python-3.9.7.tar.xz
cd Python-3.9.7/

Within the /Python-3.9.7/ directory, configure the source code and install Python:

./configure --enable-optimizations
sudo make altinstall

Using altinstall prevents overwriting any existing Python versions, allowing multiple versions to coexist on the system.

Patience is required, as this command compiles many packages used by Python. Once installation completes successfully, verify the Python version:

altinstall python

python3.9 --version

python3.9 --version

Installing Python 3.9 Modules

With Python and its dependencies installed, proceed to install desired modules. For example, to install the requests module:

python3.9 -m pip install <module>

Replace <module> with your desired module name. A comprehensive list of available modules can be found on the official page.

python3.9 -m pip install requests

Your desired Python modules should be ready for use if no errors occurred during installation.

python3.9 install requests

To list installed modules, type:

python3.9 -m pip list

python3.9 list modules

Testing the Python Installation

Let’s test your Python 3.9 installation. Create a test file with your preferred text editor, such as vi or nano:

cd Python-3.9.7
sudo nano hello.py

Enter the following code in your file, save, and exit the editor:

print("Howtoforge, HelloWorld!")

Execute the program:

python3.9 hello.py

If correctly installed, it will output “Howtoforge, HelloWorld!”.

testing python 3.9

Conclusion

In this guide, we learned how to install Python 3.9 on a Rocky Linux 8 system. You can now begin programming and developing scripts using Python.

If you have any questions or feedback, please leave a comment below.

Frequently Asked Questions (FAQ)

  • Why choose Python 3.9 over other versions?
    Python 3.9 offers new syntax features, optimizations, and security improvements that older versions may not have, making it a preferred choice for many developers.
  • What should I do if I encounter installation errors?
    Ensure all prerequisites and dependencies are installed, and consider seeking guidance from the official Python documentation or community forums.
  • Can I use Python 3.9 alongside other Python versions?
    Yes, using altinstall during manual installations allows multiple Python versions to coexist without conflicts.
  • How do I update Python in the future?
    You can update Python through the official repositories or by downloading and installing the latest release from the official Python website, following a similar process as manual installations.