centos7 shell脚本一键安装nodejs
好了,python的一键安装有了,当然nodejs也得有个一键安装,毕竟这两个东西是大家经常会用到,有需要的小伙伴可以拿去.
系统:centos 7.x(64位)
cat /root/soft_shell/auto_install_node.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 nodeversion="12.13.0" VERSIONPATTERN="[0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}" echo -n "Please input a node version number (Enter 12.13.0): " read customVersion if [ ! -z $customVersion ] then macthResult=$(echo $customVersion | grep -E -x $VERSIONPATTERN ) if [ -z $macthResult ] then echo "Please input a right version number. eg. 10.15.0 or 12.13.0" exit 1 fi nodeversion=$customVersion fi number=`echo $nodeversion|awk -F '.' '{print $1}'` if [ ! -s node-v$nodeversion-linux-x64.tar.xz ];then wget https://npm.taobao.org/mirrors/node/latest-v$number.x/node-v$nodeversion-linux-x64.tar.xz fi echo -e "\033[32m \nIn the installation... \033[0m" if [ ! -s /usr/bin/node ];then tar xf node-v$nodeversion-linux-x64.tar.xz mv node-v$nodeversion-linux-x64/ /usr/local/node ln -s /usr/local/node/bin/node /usr/bin/node ln -s /usr/local/node/bin/npm /usr/bin/npm else rm -f /usr/bin/node rm -f /usr/bin/npm rm -fr /usr/local/node tar xf node-v$nodeversion-linux-x64.tar.xz mv node-v$nodeversion-linux-x64/ /usr/local/node ln -s /usr/local/node/bin/node /usr/bin/node ln -s /usr/local/node/bin/npm /usr/bin/npm fi #if [ ! -s /etc/yum.repos.d/yarn.repo ];then # wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo # rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg # yum -y install yarn # yarn config set registry https://registry.npm.taobao.org npm config set registry https://registry.npmmirror.com --global npm config set disturl https://npmmirror.com/mirrors/node --global #fi echo -e "\nInstalled node and npm version is ... " node -v && npm -v echo -e "\033[32m \nInstall Successfully! \033[0m"
评论: