centos7 shell脚本一键安装python3.7

post by rocdk890 / 2020-2-20 11:18 Thursday linux技术
最近要安装个东西,发现要python3才能支持,为了方便以后不用进行重复性工作,我就写了个一键安装python 3.7的脚本.
系统:centos 7.x(64位)

cat /root/soft_shell/auto_install_python3.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to initialization OS."
    exit 1
fi

version="3.7.4"
echo "Please enter the version number you need:"
read -p "(Default version: 3.7.4):" version
if [ "$version" = "" ];then
	version="3.7.4"
fi
name="Python"
pyfile="$name-$version.tgz"

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install"
    exit 1
fi

rpm=`rpm -qa libffi-devel|awk -F "-" '{print $1}'`
if [ -z $rpm ];then
	yum  -y install  wget gcc gcc-c++ make openssl-devel bzip2-devel libffi-devel
else
 	echo -e "\033[40;31m libffi [found]\033[40;37m"
fi


if [ -s $pyfile ];then
	echo -e "\033[40;31m $pyfile [found]\033[40;37m"
else
	wget https://www.python.org/ftp/python/$version/$pyfile
fi

tar zxf $pyfile

cd $name-$version
./configure --prefix=/usr/local/python3 --enable-optimizations
make altinstall

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

if [ -d /root/.pip ];then
	echo -e "\033[40;31m file is [found]\033[40;37m"
else
	mkdir ~/.pip

cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
disable-pip-version-check = true
timeout = 6000
EOF
fi

pip3 install --upgrade pip

echo -e "\nInstalled Python and pip version is ... "
python3 -V && pip3 -V

echo -e "\033[32m \nInstall Successfully! \033[0m"
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-766.html

标签: centos 安装 shell install 一键 python 自动

评论: