How to install Python on CentOS 8

Python is one of the most popular programming languages in the world. The simple and easy-to-learn syntax makes Python a recognized choice for beginners and experienced developers.

Unlike other Linux distributions, on CentOS 8, Python is not installed by default.

As you may already know, two versions of Python are actively developed. Although Python is well supported and very active, Python 3 is already considered the language of today and the future.

By default, RHEL/CentOS 8 does not have a system-wide python command without a version number to avoid locking users on a specific Python version. Instead, it gives the user the choice to install, configure, and run the specified Python version. System tools such as yum use an internal Python binary file and library file.

This guide will take you to install Python 3 and Python 2 on CentOS 8.

1. Install Python 3 on CentOS 8

In order to install Python 3 on CentOS 8, run the following command as root or another sudo user:

sudo dnf install python3

To verify the installation process, enter the following command to check the Python version number:

python3 --version

At the time of writing this article, the latest version of Python 3 in the CentOS source repository is "3.6.x":

Python 3.6.8

This command will also install pip.

To run Python, you need to explicitly enter python3 and run pip by entering pip3.

You should like to install the python modules provided by the distribution via yum or dnf. Because in order to run normally on CentOS 8, they have been well supported and tested.

Only use pip in a virtual environment. Python Virtual Environments allows you to install Python modules for individual projects instead of globally.

In this way, you don't have to worry about affecting other Python projects.

Python 3 module packages use python3 as the prefix of their names. For example, to install the paramiko module, you can run:

sudo dnf install python3-paramiko

2. Install Python 2 on CentOS 8

The Python 2 package is also included in the default CentOS 8 source repository.

To install Python 2, enter the following command:

sudo dnf install python2

Enter the following command to verify the installation process:

python2 --version

The output should look like this:

Python 2.7.15

To execute Python 2, enter python2 and enter pip2 to run pip.

3. Set the default Python version (Python command without version number)

If your application expects to find the python command in the system Path, you will need to create a python command without a version number and set the default version.

To set Python 3 as a system-wide python command, please use the alternatives tool:

sudo alternatives --set python /usr/bin/python3

For Python 2, enter:

sudo alternatives --set python /usr/bin/python2

This alternatives command creates a python soft link pointing to the specified python version.

In your terminal, enter python -version, you can see the default Python version number.

To modify the default version number, please use any of the above commands. If you want to remove the python command without the version number, enter:

sudo alternatives --auto python

Four, conclusion##

In CentOS 8, Python is not installed by default.

To install Python 3, type dnf install python3. To install Python 2, type dnf install python2.

Recommended Posts

How to install Python 3.8 on CentOS 8
How to install Python on CentOS 8
R&D: How To Install Python 3 on CentOS 7
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
How to install GCC compiler on CentOS 7
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
[Practice] How to install python3.6 on Ubuntu system
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos
How to install and configure Redmine on CentOS 8