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 of Python official website:
I chose the latest version 3.8.0:
Click the corresponding version to jump to the download page of that version, scroll to the bottom of the page, and copy the source code download link:
Then use the wget
command to download on Linux, and use the tar
command to decompress the downloaded 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 decompressed directory and follow the steps below to complete the compilation and installation:
[ 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 the installation is complete, you need to configure the 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
Final verification version:
[ root@localhost /usr/local/src/Python-3.8.0]# pip3 --version
pip 19.3.1from/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 202019,09:27:22)[GCC 8.2.120180905(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]#
In CentOS7, you can install ansible directly through yum
. However, the ansible installation package is no longer provided under the default yum
source of CentOS8. Instead, you need to install it through Python's pip
command, which is why you need to install Python first.
Before installing ansible, we need to change the source of pip
, here is 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 #New storage directory for configuration files
[ root@localhost ~]# vim ~/.pip/pip.conf #Configure the download source as the source of Douban
[ global]
index-url = http://pypi.douban.com/simple
[ install]
trusted-host = pypi.douban.com
[ root@localhost ~]#
After completing the replacement of the download source, you can start to install ansible. The installation command is as follows:
[ root@localhost ~]# pip3 install ansible
Finally, verify that the installation is 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 202019,09:27:22)[GCC 8.2.120180905(Red Hat 8.2.1-3)][root@localhost ~]#
Recommended Posts