1. 检查是否安装wget:
$ wget --version
2. 如果没有安装,安装wget:
$ apt-get update
$ apt-get install wget
3. 检查是否安装成功:wget --version
4. clone node-install.sh到linux文件夹下:
$ git clone https://github.com/Dsazz/nodejs-linux-installer
5. 执行node-install.sh
$ chmod +x node-install.sh
$ ./node-install.sh (当前目录下执行方式)
$ /home/lchen/node-install.sh(非当前目录下执行方式)
6. 安装完成后检查是否成功:
$ node -v
$ npm -v
*******************************************
node-install.sh内容(手写的话,要在linux系统下编辑保存)
#!/bin/bash |
echo "Node Linux Installer by www.github.com/taaem" |
echo "Need Root for installing NodeJS" |
sudo sh -c 'echo "Got Root!"' |
echo "Get Latest Version Number..." |
{ |
wget --output-document=node-updater.html https://nodejs.org/dist/latest/ |
ARCH=$(uname -m) |
if [ $ARCH = x86_64 ] |
then |
grep -o '>node-v.*-linux-x64.tar.gz' node-updater.html > node-cache.txt 2>&1 |
VER=$(grep -o 'node-v.*-linux-x64.tar.gz' node-cache.txt) |
else |
grep -o '>node-v.*-linux-x86.tar.gz' node-updater.html > node-cache.txt 2>&1 |
VER=$(grep -o 'node-v.*-linux-x86.tar.gz' node-cache.txt) |
fi |
rm ./node-cache.txt |
rm ./node-updater.html |
} &> /dev/null |
echo "Done" |
DIR=$( cd "$( dirname $0 )" && pwd ) |
echo "Downloading latest stable Version $VER..." |
{ |
wget https://nodejs.org/dist/latest/$VER -O $DIR/$VER |
} &> /dev/null |
echo "Done" |
echo "Installing..." |
cd /usr/local && sudo tar --strip-components 1 -xzf $DIR/$VER |
rm $DIR/$VER |
echo "Finished installing!" |