Python is one of the most widely used programming languages, known for its simplicity and versatility. Whether you’re developing web applications, data science projects, or automation scripts, Python is an essential tool for developers. While CentOS 7 server comes with Python 2.x by default, many modern applications and frameworks now require Python 3. In this article, we will walk you through the steps to install Python 3 on CentOS 7, ensuring you can work with the latest version of Python.
Before installing Python 3, you need to ensure your system is updated and that you have root or sudo privileges. This will help avoid any permission issues during installation.
Access to a CentOS 7 server
Root or sudo privileges
Basic knowledge of using the command line
It’s always a good idea to update your system packages before installing new software. Open a terminal and run the following command to update your CentOS 7 system:
This will ensure that all existing packages are up to date and any security patches are applied.
The Extra Packages for Enterprise Linux (EPEL) repository contains additional packages that are not included in the default CentOS repositories. To install Python 3 on CentOS 7, you will need to enable the EPEL repository first.
To enable the EPEL repository, run the following command:
Once the repository is enabled, your system will have access to a wide range of additional packages, including Python 3.
Now that the EPEL repository is enabled, you can proceed to install Python 3. CentOS 7 uses the yum
package manager, so you can use the following command to install Python 3:
This command will install Python 3 and the associated tools, including pip
(Python’s package manager).
After the installation is complete, verify that Python 3 has been installed correctly by checking the version. Run the following command to check the Python version:
You should see an output similar to:
This confirms that Python 3 has been successfully installed on your CentOS 7 system.
pip
for Python 3 (Optional)pip
is the package manager for Python that allows you to install additional Python packages. While pip
is often installed automatically along with Python 3, you can verify if it was installed by running:
If pip
is not installed, you can install it manually with the following command:
Once installed, you can use pip
to install additional Python packages:
By default, CentOS 7 uses Python 2.x as the system Python. If you’d like to make Python 3 the default version when running the python
command, you can create an alias.
To make this change, open the .bash_profile
file for your user:
Then, add the following line at the end of the file:
Save and exit the file (CTRL+X
, then Y
, and press Enter
). To apply the changes, reload your profile:
Now, when you run the python
command, it will invoke Python 3.
If you need additional libraries or development tools, you can install them using yum
. For example, if you want to install the development tools needed for compiling Python extensions, you can run:
This will install a set of tools that can help you build and manage Python packages and extensions.
Installing Python 3 on CentOS 7 is a straightforward process. By following the steps outlined in this article, you’ll be able to set up Python 3 on your CentOS 7 system and start developing with the latest version of Python.
Remember, Python 3 is now the standard for most modern applications, and it’s important to ensure you are working with the latest version. If you ever need to update Python 3, you can do so by running:
Now you’re ready to take full advantage of Python 3’s powerful features, libraries, and frameworks on your CentOS 7 server!