wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar -xf Python-3.6.2.tgz
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
./configure --prefix=/opt/python362
告诉编译器,python安装的目录在哪里,--prefix就是指定安装路径的make && make install
echo $PATH,可以查看环境变量,`/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` 配置环境变量就需要对PATH这个变量重新赋值 临时赋值 `PATH=/opt/python362/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` 永久赋值 编辑/etc/profile文件,底部写入`PATH=/opt/python362/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin` 然后source /etc/profile进行重载, source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录
针对上面的所有步骤,写了个脚本,可以用source去加载自动执行
cd /home && yum install -y tree && yum install -y vim && yum install -y make && yum install -y wget && wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz && #下tar包 tar -xf Python-3.6.2.tgz && #解压缩 yum install gcc patch libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel xz-devel -y && #安装gcc以及依赖文件 cd /home/Python-3.6.2 && #这一步很重要configure命令必须先进入这个解压的文件目录 ./configure --prefix=/opt/python362 && #释放make文件,并安装到指定目录 /opt/python362 make && make install && #编译 echo "PATH=/opt/python362/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /etc/profile && #写入环境变量 source /etc/profile #不重启加载环境变量