Python is a popular, high-level programming language known for its simplicity and versatility. It is used for a wide range of applications, including web development, data analysis, machine learning, and automation.
In this article, we will show you how to install Python 3.9 on Rocky Linux 8. This guide is intended for users who want to try out the latest version of Python on their Rocky Linux system, or for developers who need to use the latest features in their Python projects.
Before we begin, it’s important to note that Rocky Linux 8 comes with Python 3.6 pre-installed. This version of Python is sufficient for most users and you should only follow the steps in this article if you need to use a newer version of Python.
Prerequisites
Before you begin, you should have a basic understanding of the Linux command line, and be familiar with the sudo command. You should also have a user account with sudo privileges on your Rocky Linux system.
In addition, you will need the following dependencies installed on your system:
build-essential: This package includes the basic tools needed to build software from source.zlib1g-dev: This package provides the header files and static libraries needed to compile programs that use the zlib compression library.libncurses5-dev: This package provides the header files and static libraries needed to compile programs that use the ncurses library.libgdbm-dev: This package provides the header files and static libraries needed to compile programs that use the GNU DBM library.libnss3-dev: This package provides the header files and static libraries needed to compile programs that use the NSS library.libssl-dev: This package provides the header files and static libraries needed to compile programs that use the OpenSSL library.libreadline-dev: This package provides the header files and static libraries needed to compile programs that use the GNU readline library.libffi-dev: This package provides the header files and static libraries needed to compile programs that use the Foreign Function Interface (FFI) library.wget: This package provides thewgetcommand-line utility, which is used to download files from the internet.
To install these dependencies, open a terminal window and run the following command:
sudo apt update && sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
Downloading the Python Source Code
The next step is to download the Python 3.9 source code. This can be done using the wget command. Open a terminal window and run the following command:
wget <https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz>
This will download the Python 3.9 source code as a .tgz file to your current directory.
Extracting the Python Source Code
Once the download is complete, you can extract the source code from the .tgz file using the tar command. Run the following command to extract the source code:
tar xvf Python-3.9.0.tgz
This will create a new directory named Python-3.9.0 that contains the Python 3.9 source code.
Compiling the Python Source Code
The next step is to compile the Python source code. This is a two-step process. First, you need to run the ./configure script, which will check your system for the necessary dependencies and create the makefiles needed to build Python.
To run the ./configure script, open a terminal window and navigate to the Python-3.9.0 directory, then run the following command:
./configure --enable-optimizations
This will run the ./configure script with the --enable-optimizations flag, which will enable advanced optimization features that can improve the performance of the Python interpreter.
Once the ./configure script has completed, you can compile the Python source code by running the make command. This command will use the makefiles generated by the ./configure script to build the Python interpreter and standard library.
To compile the Python source code, run the following command:
make -j 8
This command will use eight parallel processes to compile the Python source code, which can speed up the build process on systems with multiple CPU cores. The build process may take several minutes to complete, depending on the speed of your system.
Installing Python 3.9
Once the Python source code has been compiled, you can install it on your system by running the make altinstall command. This command will install the Python interpreter and standard library, but will not replace the version of Python that is included with Rocky Linux.
To install Python 3.9, open a terminal window and run the following command:
sudo make altinstall
This will install Python 3.9 in the /usr/local/bin directory, which is separate from the version of Python that comes pre-installed on Rocky Linux.
Verifying the Installation
Once Python 3.9 has been installed, you can verify that it was installed correctly by running the python3.9 command. This command will launch the Python 3.9 interpreter and print its version number.
To verify the installation, open a terminal window and run the following command:
python3.9 -V
If the installation was successful, you should see output similar to the following:
Python 3.9.0
This indicates that Python 3.9 was installed successfully on your Rocky Linux system.
Conclusion
In this article, we showed you how to install Python 3.9 on Rocky Linux 8. We explained the prerequisites that are required, and provided detailed instructions for downloading and compiling the Python source code. We also showed you how to install Python 3.9 and verify the installation.
With the steps in this article, you should now be able to install the latest version of Python on your Rocky Linux system and use it for your projects.
Remember, if you encounter any issues during the installation process, please refer to the official Python documentation for further assistance.