Python is a programming language that can be used to create just about anything. From full-scale games to web applications, and even simple scripts for your PC or Mac. Python has been around since the late 1980s and continues to be one of the most popular languages in use today.

Today’s tutorial will show you how to install Python 3.9 programming language on a Rocky Linux 8 system.

Prerequisites

  • A Rocky Linux 8 system. Any relatively recent version of Rocky Linux should work fine with this instructions. 
  • A non-root user with sudo privilege set up on your Rocky system.

Updating the System

The first thing we need to do is update the system software packages. This ensures that our entire system has been updated, and updated to the latest stable versions, before we start installing Python.

sudo dnf -y update

Install Python 3.9 Using the Official Repository

As of this writing, the default Rocky Linux 8 AppStream repository has Python v3.7, v3.8, and v3.9.

Run the following command to install the latest Python version.

sudo dnf install python39

Click Y and hit Enter when prompted. The installation process will begin.

<img alt="install python39" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/install_python39.png617ac70de753d.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

Once the installation is complete, run the following command to verify that your Python version.

python3.9 --version

<img alt="python3.9 –version" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/python39_–version.png617ac70e27623.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="52" loading="lazy" src="data:image/svg xml,” width=”663″>

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

Installing Python 3.9 Manually

If you do not have access to the AppStream repository or prefer installing from a different source, you can install Python 3.9 manually using the Python 3.9 archive. To begin the installation process, open up your terminal and run the following command to install the necessary packages to compile Python packages on Rocky Linux 8.

sudo dnf groupinstall "Development Tools" -y

Next, run the following command to install the necessary dependencies. Such as openssl-devel, libffi-devel.

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

Now, dowload the latest version of Python using the wget command. Extract the zip file, and move into the extracted directory.

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/

Once you in the /Python-3.9.7/ directory. Run the following command to configure the source code and install the Python packages.

./configure --enable-optimizations
sudo make altinstall

We use altinstall instead to make install because the latter will overwrite any existing Python binary. We need Python 3.9 to coexist on the same system with 3.7 or any other version of Python installed. Otherwise, you will not be able to use multiple versions at once.

This command takes quite some time to complete because this command compiles a large number of packages used by Python. Please be patient and wait for the installation to complete.

If the Python installation was successful, you should get a message like below.

<img alt="altinstall python" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/altinstall_python.png617ac70e4cd1b.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

Run the following command to verify your Python version.

python3.9 --version

 You should get an output like the one below.

<img alt="python3.9 –version" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/python39_–version_2.png617ac70e7985a.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="51" loading="lazy" src="data:image/svg xml,” width=”669″>

Installing Python 3.9 Modules

Now that we have Python and all of its dependencies installed, we can install our desired modules.

Run the following command to download and install the requests module for Python 3.9.

python3.9 -m pip install 

Where: is the name of the module that you want to install. You can get a comprehensive list of available modules on the official page

For example, we will install the requests module.

python3.9 -m pip install requests

If no errors are encountered during the installation process, then your desired Python modules should be ready for use on your system.

<img alt="python3.9 install requests" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/python39_install_requests.png617ac70e95b0a.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="282" loading="lazy" src="data:image/svg xml,” width=”662″>

To see which modules are installed on the server, type this command.

python3.9 -m pip list

You should get an output like the one below.

<img alt="python3.9 list modules" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/python39__list_modules.png617ac70eb90db.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="164" loading="lazy" src="data:image/svg xml,” width=”654″>

Testing the Python Installation

Now that you have Python 3.9 installed, let’s test it. Run the following command to create create a test file with your favorite text editor, such as vi or nano. The name of this file is how you will run the Python program from now on without specifying the full path to the file.

cd Python-3.9.7
sudo nano hello.py

Copy and paste the following code into your file, save your changes to the file, and exit your editor.

print("Howtoforge, HelloWorld!")

Now we can run this program by typing:

python3.9 hello.py

If all is working correctly you should get a Hello World message.

<img alt="testing python 3.9" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/testing_python_39_2.png617ac70edec23.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="53" loading="lazy" src="data:image/svg xml,” width=”648″>

Conclusion

In this guide, we have learned how to install Python 3.9 script language on Rocky Linux 8. We can now use Python for programming and writing scripts.

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