linux-tutorial/codes/linux/ops/soft/nodejs-install.sh

39 lines
934 B
Bash
Raw Normal View History

2018-02-01 16:34:02 +08:00
#!/usr/bin/env bash
2019-05-07 12:07:59 +08:00
cat << EOF
###################################################################################
# 安装 Nodejs 脚本
2019-05-07 14:29:16 +08:00
# @system: 适用于所有 linux 发行版本。
# @author: Zhang Peng
###################################################################################
2018-02-01 16:34:02 +08:00
2019-05-07 12:07:59 +08:00
EOF
2019-05-09 11:26:06 +08:00
if [[ $# -lt 1 ]] || [[ $# -lt 2 ]];then
echo "Usage: sh nodejs-install.sh [version] [path]"
echo -e "Example: sh nodejs-install.sh 10.15.2 /opt/nodejs\n"
fi
2019-05-07 12:07:59 +08:00
version=10.15.2
if [[ -n $1 ]]; then
version=$1
fi
2018-02-01 16:34:02 +08:00
. ~/.nvm/nvm.sh
nvm --version
execode=$?
2019-02-22 18:02:38 +08:00
if [[ ${execode} != 0 ]]; then
echo -e "\n>>>>>>>>> install nvm"
rm -rf ~/.nvm
2019-05-07 12:07:59 +08:00
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm --version
fi
2019-05-09 11:26:06 +08:00
echo "Current execution: install nodejs ${version} to ${root}"
2019-05-07 12:07:59 +08:00
echo -e "\n>>>>>>>>> install nodejs by nvm"
nvm install ${version}
nvm use ${version}
node --version