说明:CentOS 7最小化安装,默认Python 2.7 ,开发需要安装python3.6.1 。
1、检查python版本
[[email protected] ~]# python -V
Python 2.7.5
[[email protected] ~]#
2、安装必要的库文件
# yum -y install zlib zlib-devel gcc
3、下载python3.6.1到/usr/local目录
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
4、解压安装
# xz -d Python-3.6.1.tar.xz
# tar -xvf Python-3.6.1.tar
# cd Python-3.6.1/
# ./configure prefix=/usr/local/python3
# make && make install
5、永久添加环境变量
# vim/etc/profile
添加 export PATH="$PATH:/usr/local/python3/bin"
添加完成后 source /etc/profile
**临时添加环境变量为 # export PATH="$PATH:/usr/local/python3/bin" 终端结束后环境变量生效
6、打开python3.6
[[email protected] ~]# python3
Python 3.6.1 (default, May 19 2017, 04:11:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
7、修改/usr/bin/python链接
# cd/usr/bin
# mv python python.bak
# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
修改后可直接用 # python打开python3