Ubuntu下自动安装NodeJs的脚本,
nodejs_setup.sh脚本代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 1#!/bin/bash
2# install and configure nodejs
3# USAGE: sh nodejs_setup.sh version,
4# e.g. sh node_setup.sh 0.10.31
5#
6apt-get install -y g++ gcc python build-essential
7
8if [ $# -eq 0 ]; then
9 VERSION=0.10.31
10else
11 VERSION=$1
12fi
13
14echo "install v$VERSION of node..."
15sleep 1
16
17NODE_VERSION=node-v$VERSION
18NODE_TAR=${NODE_VERSION}.tar.gz
19DOWNLOAD_HOME=/home/leekwen/Downloads
20
21echo -n 'Checking DOWNLOAD_HOME : '
22if [ ! -f $DOWNLOAD_HOME ]; then
23 echo 'not found, create it...'
24 mkdir -p $DOWNLOAD_HOME
25else
26 echo 'found'
27fi
28
29cd $DOWNLOAD_HOME
30rm -rf $NODE_VERSION
31
32echo -n "Checking $NODE_VERSION : "
33if [ -f $NODE_TAR ]; then
34 echo 'found'
35else
36 echo "download $NODE_VERSION..."
37 wget -c http://nodejs.org/dist/v${VERSION}/${NODE_TAR}
38fi
39
40tar -zxvf $NODE_TAR
41cd $NODE_VERSION
42
43./configure
44make
45make install
46
47
参考:https://github.com/chosen0ne/nodejs-setup-script/blob/master/node_setup.sh
增加判断操作系统的代码,支持Ubuntu/CentOS系统,其它的操作系统请自行添加,具体代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 1#!/bin/bash
2# install and configure nodejs
3# USAGE: sh nodejs_setup.sh version,
4# e.g. sh node_setup.sh 0.10.31
5#
6
7OS=`head -n 1 /etc/issue |awk '{print $1}'`
8
9if [ "$OS"x = "Ubuntu"x ]; then
10 echo "This System is Ubuntu"
11 apt-get install -y g++ gcc python build-essential
12elif [ "$OS"x = "CentOS"x ]; then
13 echo "This System is CentOS"
14 yum install -y gcc-c++ gcc
15fi
16
17if [ $# -eq 0 ]; then
18 VERSION=0.10.31
19else
20 VERSION=$1
21fi
22
23echo "install v$VERSION of node..."
24sleep 1
25
26NODE_VERSION=node-v$VERSION
27NODE_TAR=${NODE_VERSION}.tar.gz
28DOWNLOAD_HOME=$HOME/nodejs-v$VERSION
29
30echo -n 'Checking DOWNLOAD_HOME : '
31if [ ! -f $DOWNLOAD_HOME ]; then
32 echo 'not found, create it...'
33 mkdir -p $DOWNLOAD_HOME
34else
35 echo 'found'
36fi
37
38cd $DOWNLOAD_HOME
39rm -rf $NODE_VERSION
40
41echo -n "Checking $NODE_VERSION : "
42if [ -f $NODE_TAR ]; then
43 echo 'found'
44else
45 echo "download $NODE_VERSION..."
46 wget -c http://nodejs.org/dist/v${VERSION}/${NODE_TAR}
47fi
48
49tar -zxvf $NODE_TAR
50cd $NODE_VERSION
51
52./configure
53make
54make install
55