脚本
#安装node#下载node、npm国内镜像(推荐)# 判断是否安装了nodeif type -p node; thenecho "node has been installed."elsemkdir -p /home/zenglg cd /home/zenglgwget https://registry.npmmirror.com/-/binary/node/v10.14.1/node-v10.14.1-linux-arm64.tar.gz#解压并重命名文件夹tar -xvf node-v10.14.1-linux-arm64.tar.gzrm -rf /usr/local/nodemv -f node-v10.14.1-linux-arm64 /usr/local/node#设置环境变量,使其生效 # 检查原先是否已配置node环境变量checkNodeExist(){node1=$(grep -n "export NODE_HOME=/usr/local/node" /etc/profile | cut -f1 -d':')if [ -n "$node1" ];thensed -i "${node1}d" /etc/profilefinode2=$(grep -n "export PATH=$NODE_HOME/bin:$PATH" /etc/profile | cut -f1 -d':')if [ -n "$node2" ];thensed -i "${node2}d" /etc/profilefi}checkNodeExistecho "export NODE_HOME=/usr/local/node" >> /etc/profilesource /etc/profileif [[ ${PATH} =~ ${NODE_HOME}/bin ]]; thenecho " NODE_HOME has been set"elseecho "export PATH=$NODE_HOME/bin:$PATH" >> /etc/profileecho "setting NODE_HOME path successful."fi#保存刷新source /etc/profilefi
node -v
出现下图说明安装成功