-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.sh
executable file
·48 lines (37 loc) · 996 Bytes
/
node.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
48
SRC_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
NVM_VERSION="0.39.5"
NODE_DEFAULT="lts/hydrogen"
NODE_VERSIONS=(
"lts/fermium"
"lts/gallium"
"lts/hydrogen"
)
echo "Setup nvm/Node..."
echo ""
echo "This will install:"
echo " nvm v${NVM_VERSION}"
for i in "${NODE_VERSIONS[@]}"
do
echo " Node ${i}"
done
echo "This will also write load-nvmrc script into .zshrc if needed."
echo ""
# Install nvm
if [ -e ${HOME}/.nvm/nvm.sh ]; then
echo "Skipping because nvm already exists. Run ./unnode.sh to remove it."
else
# Install nvm if needed and source it.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
fi
source ${HOME}/.nvm/nvm.sh
# Install each version of Node
for i in "${NODE_VERSIONS[@]}"
do
echo "Install Node ${i}"
nvm install $i
# Set up user npm configuration
npm config set depth 0
done
# Switch on the default Node and install all the global npm packages to it.
nvm alias default ${NODE_DEFAULT}
nvm use default