Logo

Guide to Installing Python 3 Latest Version on CentOS 7 [2 Methods Inside]

Try this guide with our instant dedicated server for as low as 40 Euros

update python

Python, a widely used programming language, is favored across various Linux distributions, including CentOS 7. 

In many cases, the first challenge developers face is to install Python on CentOS 7 and similar RHEL-based distributions. You need to manually install the development components (compiler and libraries) because Python is not preinstalled on CentOS 7.

In this guide, we will present two straightforward installation options for Python 3 on CentOS 7. You can select the method based on your preferred version, ensuring a smooth setup.

The Prerequisites to Install and Update Python 3 on CentOS 7

Before trying out the two methods we will cover later on, make sure you have the following:

  • A system running a stable recent CentOS7 version
  • A user account with root or sudo access
  • You have the YUM package manager installed and active

Table Of Contents

  1. Python Installation on CentOS 7
    1. Option #1: Install Python Using the YUM Package Manager
    2. Option #2: Install Python From the Source Code
  2. Conclusion
  3. FAQs

Python Installation on CentOS 7

Let’s go into the details of the two ways to install Python 3 on CentOS7:

Option #1: Install Python Using the YUM Package Manager

At the moment of writing this tutorial, the latest Python 3 version available in the YUM package manager is 3.6.8. The process of installing version 3.6.8, has the following steps.

Step #1: Update the System Repository

Start by updating the local packages with the following command:

# sudo yum update -y

Step #2: Download the Python Repository

You now should download the Python 3 repository before you can install it on CentOS7. For older releases, add an IUS repository that offers newer versions, including Python 3.

To add the IUS repository to the system repository, execute the following command:

# sudo yum install https://repo.ius.io/ius-release-el$(rpm -E '%{rhel}').rpm

After installation, update the repository by repeating Step #1.

# sudo yum update -y

Step #3: Install Python 3

Now that you have added the Python repository to the system index, install Python 3 with this terminal command:

# sudo yum install -y python3

After installation, ensure ‘python3’ and its dependencies are installed as displayed in the output.

sudo yum install -y python3

Step #4: Verify Python 3 Installation

Verify Python 3 installation by running the following command:

# python3 --version

This command will print the Python 3 version information in the terminal.

Python 3 version information in the terminal

Option #2: Install Python From the Source Code

If you want the latest major release, Python 3.9.6 on your CentOS7 system, download the source code and follow these additional setup steps.

Step #1: Update the Package Index

Start by installing the necessary packages and dependencies with the following commands:

# sudo yum groupinstall "Development Tools" -y

# sudo yum install gcc open-ssl-devel bzip2-devel libffi-devel -y

sudo yum install gcc open-ssl-devel bzip2-devel libffi-devel -y

Step #2: Get wget and Download Python

We will utilize wget to fetch the preferred Python version. If wget isn’t installed, install it by running the following command:

# sudo yum install wget -y

Next, use wget to download Python 3.9.6. The command in this context will be as follows:

# wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz

wget

Step #3: Compile Python Files

Start by extracting the package contents with the following command:

# sudo tar xzf Python-3.9.6.tgz

Navigate to the directory with this cd command:

cd Python 3.9.6

In the Python directory, use these two commands to compile the source code into an installation package:

# ./configure --enable-optimizations

# make altinstall

The make command builds the installer package. The altinstall command triggers the system to create a secondary installation of this Python version. This prevents the default Python version from being replaced. As a result, you can have more than one version of Python on your system.

Step #4: Check Python Version

Verify the installation by confirming the Python version with this command:

# python3.9 --version

You should see:

python3.9 --version

Conclusion

This guide has offered two distinct methods for installing Python 3 on CentOS 7. Now that you’re all set, dive into Python’s basics by experimenting with simple scripts, such as retrieving the current time and date, or delve into file handling with Python’s built-in methods, covering tasks like file creation, opening, and closure.

FAQs

Q. What is the default version of Python available for CentOS 7?

The default Python version on CentOS 7 is usually an older release. Further steps are necessary to install the latest stable version at the time of writing. 

Q. Can an experienced developer install Python 3 on CentOS 7 without root user privileges? 

Yes, an experienced developer can install Python 3 on CentOS 7 without root user privileges by utilizing third-party repositories and following the additional installation step outlined in this guide. 

Q. What is the process of source installation for Python 3 on CentOS 7?

Source installation involves downloading the Python archive file and compiling it manually. This method allows users to access the latest stable version of Python, bypassing the limitations of default package versions provided by CentOS 7 operating systems. 

Q. How do Software Collections affect the installation of Python on CentOS 7? 

Software Collections provides additional software packages, including updated versions of Python, for CentOS 7 operating systems. This enables users to access newer Python versions without altering the default location of system-installed Python binaries. 

Q. Is Python a versatile programming language suitable for beginners on CentOS 7?

Yes, Python is a versatile programming language and a popular choice for beginners on CentOS 7. With its user-friendly syntax and extensive community support, Python provides an ideal programming environment for learners to start building their coding skills. 

Q. Can Python be installed on CentOS 7 using the apt package manager? 

Python cannot be installed on CentOS 7 using the apt package manager, as it is designed for Debian-based operating systems. CentOS 7 utilizes the yum package manager as its base package repository, making it the primary choice for installing Python through the command line interface. 

Q. Can you provide a comprehensive guide for alternate installation methods of Python on CentOS 7? 

Yes, alternate installation methods, such as using alternate installation tar xzf or specifying a custom installation location, can be explored for installing Python on CentOS 7. However, please note that these methods may require additional packages and familiarity with prompt characters. Instructions for installation on Windows using <specific method> are also available. 

Q. Is a Linux Installation Guide available for installing Python on CentOS 7? 

A Linux Installation Guide provides step-by-step instructions for installing Python on CentOS 7. It includes details on updating system packages, handling additional software repositories, resolving toolkit dependencies, and ensuring correct dependencies for a smooth installation process. 

Q. What should I do if I encounter issues with the startup file after installing Python on CentOS 7?

If you encounter issues with the startup file, ensure that all dependencies are correctly installed and that the correct version of Python is being referenced. Additionally, verify that there are no conflicts with other applications or wrong applications being referenced in the startup file. Utilizing bash scripts and standard library modules can assist in troubleshooting and resolving startup file issues.

Q. What installation methods are popular among professional and advanced developers for installing Python on CentOS 7?

Professional and advanced developers often prefer installation methods such as downloading Python source code and utilizing source tarballs for installing Python on CentOS 7. These methods provide greater flexibility and control over the installation process, allowing developers to customize their Python environment as needed. 

Q. How can I use update-alternatives to manage multiple Python versions on CentOS 7?

To manage multiple Python versions on CentOS 7, you can use the $ sudo update-alternatives command. This command allows you to specify which version of Python you want to use as the default interpreter by configuring symbolic links to the appropriate binaries. This approach is particularly useful for developers who need to work simultaneously with different versions of Python or switch between versions for different projects. 

Q. What precautions should command line developers take when using Python on CentOS 7?

Command line developers, especially professionals, should be cautious when scripting on CentOS 7 with Python. Specify Python versions accurately with commands like $ python3 -V or python –version. Also, ensure proper setup of command line tools and use -m venv option for virtual environments. 

Try this guide with our instant dedicated server for as low as 40 Euros