-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-node.sh
More file actions
42 lines (35 loc) · 1.14 KB
/
Copy pathinstall-node.sh
File metadata and controls
42 lines (35 loc) · 1.14 KB
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
#!/bin/bash
#============================================================#
# Exit immediately if a command exits with a non-zero status #
#============================================================#
set -e
#==================================================#
# Check if necessary environment variables are set #
#==================================================#
if [ -z "$NODE_VERSION" ]; then
echo "Error: NODE_VERSION is not set."
exit 1
fi
if [ -z "$NPM_VERSION" ]; then
echo "Error: NPM_VERSION is not set."
exit 1
fi
#=================#
# Install Node.js #
#=================#
echo "Installing Node.js version ${NODE_VERSION}..."
curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - || {
echo "Error: Failed to download Node.js setup script."
exit 1
}
apt-get install -y --no-install-recommends nodejs
#=============#
# Install npm #
#=============#
echo "Installing npm version ${NPM_VERSION}..."
npm install -g "npm@${NPM_VERSION}"
#=============#
# Cleaning Up #
#=============#
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
echo "Node.js and npm installation completed successfully."