-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodejs_util.sh
executable file
·106 lines (93 loc) · 3.91 KB
/
nodejs_util.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#
# jim380 <admin@cyphercore.io>
# ============================================================================
#
# Copyright (C) 2019 jim380
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# ============================================================================
NODE_VERSION="10"
function main {
echo -e "What would you like to do:\n\n1) Remove Nodejs\n2) Install Nodejs\n3) Remove then tnstall Nodejs\n\nEnter number down below:"
read input
case $input in
"1")
remove
;;
"2")
echo -e "\nWhat major version of Nodejs would you like to install?\nExample: enter 13 if you want to install v13.x\nFind releases here: https://nodejs.org/en/download/releases/\n"
read -p NODE_VERSION
install
;;
"3")
echo -e "\nWhat major version of Nodejs would you like to install?\nExample: enter 13 if you want to install v13.x\nFind releases here: https://nodejs.org/en/download/releases/\n"
read -p NODE_VERSION
remove
install
;;
*)
echo -e "Invalid input - $input\n"
;;
esac
}
function remove {
echo "-----------------------------------------"
echo " Remove nvm "
echo "-----------------------------------------"
sudo rm -rf ~/.nvm
hash -r
echo "-----------------------------------------"
echo " Remove Node "
echo "-----------------------------------------"
sudo npm uninstall -g n
sudo apt-get purge -y nodejs npm
sudo apt-get purge -y nodejs-legacy npm
sudo apt -y autoremove
echo "-----------------------------------------"
echo " File Clean-up "
echo "-----------------------------------------"
sudo rm -rf /usr/local/lib/node_modules/npm
sudo rm -rf /usr/local/lib/node_modules/n
sudo rm -f /usr/local/bin/node
sudo rm -f /usr/local/bin/npm
sudo rm -f /usr/bin/node
sudo rm -rf /usr/local/n/versions/node
echo "Nodejs has been successfully removed."
}
function install {
echo "-----------------------------------------"
echo " Install Node "
echo "-----------------------------------------"
curl -sL https://deb.nodesource.com/setup_$NODE_VERSION.x | sudo -E bash -
sudo apt-get install -y nodejs
echo "-----------------------------------------"
echo " Path Optimization "
echo "-----------------------------------------"
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH="~/.npm-global/bin:$PATH"'>>~/.profile
source ~/.profile
echo "Nodejs has been successfully installed."
node -v
npm -v
}
main