CentOS 6.9 compile and install python
Python official website: https://www.python.org/
1. Check the CentOS version and the system default Python version:
cat /etc/redhat-release
python -V
**2. Compile and install Python-3.6.1: **
1、 Install dependent packages:
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-develreadline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel man
2、 Set the current system time of CentOS6:
date 040413022017.30
date
3、 Configure host name resolution: # vim /etc/hosts --> 127.0.0.1 localhost
4、 Compile and install Python-3.6.1:
tar xf Python-3.6.1.tar.xz -C /usr/src
cd /usr/src/Python-3.6.1
. /configure --prefix=/usr/local/python3.6.1 --enable-shared --enable-profiling--enable-optimizations --disable-ipv6 --with-threads --with-pymalloc --with-fpectl--enable-loadable-sqlite-extensions
make && make install //This step needs to be tested, which takes a long time
4、 Change the default Python version of CentOS 6.9 to 3.6.1:
mv /usr/bin/python /usr/bin/python2.6.6-old
ln -s /usr/local/python3.6.1/bin/python3 /usr/bin/python
ln -s /usr/local/python3.6.1/bin/pip3 /usr/bin/pip
5、 Add to the PATH environment variable:
vim /etc/profile.d/python3.6.1.sh
exportPATH=/usr/local/python3.6.1/bin:$PATH
. /etc/profile.d/python3.6.1.sh
echo $PATH
6、 Configuration header file:
ln -sv /usr/local/python3.6.1/include /usr/include/python3.6.1
7、 Configuration library file:
echo "/usr/local/python3.6.1/lib" >/etc/ld.so.conf.d/python3.6.1.conf
cat /etc/ld.so.conf.d/python3.6.1.conf
ldconfig
8、 Configure man help files:
vim /etc/man.config, add the following code:
MANPATH /usr/local/python3.6.1/share/man
9、 View the configured Python version:
python -V
python3 -V
3. Modify the Python version in yum to the original 2.6.6 version of the system:
After upgrading Python, yum cannot be used:
vim /usr/bin/yum, modify the "#!/usr/bin/python" in the first line to "#!/usr/bin/python2.6.6-old"