Install Python 3 and ANSI ble under CentOS 8

Compile and install Python 3

First, install some dependency packages required for compilation through yum:

[root@localhost ~]# yum install -y wget gcc make libffi-devel zlib*

Enter the download address on Python official website:

https://www.python.org/downloads/source/

I chose the latest version of 3.8.0:

Click the corresponding version to jump to the download page of the version, scroll to the bottom of the page, and copy the source download link:

Then use wget command on Linux to download, and use tar command to decompress and download the good source package:

[root@localhost ~]# cd /usr/local/src
[root@localhost /usr/local/src]# wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
[root@localhost /usr/local/src]# tar -zxvf Python-3.8.0.tgz

Enter the directory after decompression, and complete the compilation and installation as follows:

[root@localhost /usr/local/src]# cd Python-3.8.0
[root@localhost /usr/local/src/Python-3.8.0]# ./configure --prefix=/usr/local/python
[root@localhost /usr/local/src/Python-3.8.0]# make && make install

After installation, you need to configure the following system environment variables to use Python commands:

[root@localhost ~]# vim /etc/profile
PYTHON_HOME=/usr/local/python
export PATH=$PATH:$PYTHON_HOME/bin
[root@localhost ~]# source /etc/profile

Last verified version:

[root@localhost /usr/local/src/Python-3.8.0]# pip3 --version
pip 19.3.1 from /usr/local/python/lib/python3.8/site-packages/pip (python 3.8)
[root@localhost /usr/local/src/Python-3.8.0]# python3
Python 3.8.0 (default, Nov 20 2019, 09:27:22) 
[GCC 8.2.1 20180905 (Red Hat 8.2.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost /usr/local/src/Python-3.8.0]# 

Install ansible through pip3

In CentOS7, ansible can be installed directly from yum. However, the default Yum source of CentOS 8 no longer provides an ansible installation package. Instead, you need to install it through Python pip command. That's why you need to install Python first.

Before installing ansible, we need to change the source of pip. Here we take the source of Douban as an example. First, execute the following command to install Douban source:

[root@localhost ~]# pip3 install xlrd -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

Then create a new pip configuration file in the user's home directory. The steps are as follows:

[root@localhost ~]# mkdir ~/.pip  # Create a new directory for the profile
[root@localhost ~]# vim ~/.pip/pip.conf  # Configure download source as Douban source
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com
[root@localhost ~]# 

After you have finished replacing the download source, you are ready to install ansible. The installation command is as follows:

[root@localhost ~]# pip3 install ansible

Finally, verify that the installation was successful:

[root@localhost ~]# ansible --version
ansible 2.9.1
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/python/lib/python3.8/site-packages/ansible
  executable location = /usr/local/python/bin/ansible
  python version = 3.8.0 (default, Nov 20 2019, 09:27:22) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
[root@localhost ~]#

Keywords: Linux Python ansible pip yum

Added by hookit on Wed, 20 Nov 2019 16:53:43 +0200