How to Install Python on CentOS — Python Tutorial
Introduction
Python is a high-level, dynamic, general-purpose language. It was developed by Guido Van Rossum in 1991. Python’s syntax allows developers to use fewer lines of code than any other programming language. It basically focuses on the code readability of programs. Python 2.7 is installed by default on CentOS, but we can install other versions like Python 3.5 and 3.6. In this tutorial, we are learning how to install Python 3.6.3 on CentOS.
Prerequisites
- CentOS
- Log in as an administrator on the terminal
- Yum must be configured on the system.
Installation
Installation includes the following steps:
1. Install IUS Community Repository
In order to install Python 3.6 on CentOS, we first need to install the IUS community repository, which provides extra packages for Enterprise Linux. Execute the following command to install the IUS community repository:
$ sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm
2. Install Python 3
Execute the following command to install Python 3.6 on CentOS:
$ sudo yum install python36u
3. Verify Python
To verify if we have installed the correct version of Python, we just need to type python 3.6 -V on the terminal. The command will show the version installed, which is 3.6.4 in my case.
4. Working on Python’s script mode
Just type python3.6 on the terminal to enter Python’s script mode. We can execute the Python statements on this shell. Since Python 2 is by default installed on CentOS, typing python on the terminal takes us to the Python 2 shell, so we have to type python3.6 to work on the desired Python shell.
Execute the valid Python statements, which get interpreted and show the desired output on the terminal as shown below.
Hence, we have installed and can get started with Python 3.