-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodejs-npm-pm2-install.sh
More file actions
75 lines (53 loc) · 2.48 KB
/
nodejs-npm-pm2-install.sh
File metadata and controls
75 lines (53 loc) · 2.48 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
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
#!/bin/bash
#################################################################################
# Script Name: nodejs-npm-pm2-install.sh
# Description: script that installs nodejs, npm and pm2 on a Raspbery Pi 4b
# Author: Adrian Ambroziak
# Email: adrian.ambroziak@gmail.com
#################################################################################
# NVM (Node Version Manager) is a bash script that allows you to install and manage multiple Node.js versions.
# Use this method if you need to install a specific Node.js version or if you need to have more than one Node.js versions installed on your Raspberry Pi.
# To install nvm run the following curl command which will download and run the nvm installation script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
# run the following to use nvm now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# Read the explanation about version installation: https://linuxize.com/post/how-to-install-node-js-on-raspberry-pi/
#install the long term supported version
nvm install --lts
# Check the version
node -v
npm -v
#turn off the iritating fund info
#see details here: https://stackoverflow.com/questions/58972251/what-does-x-packages-are-looking-for-funding-mean-when-running-npm-install
npm config set fund false --global
#install pm2 latest package
npm install -g pm2@latest
#perform an upgrade to version 8.4.0
npm install -g npm@8.4.0
#fix after upgrade
npm audit fix
#audit check
npm audit
#install uuid latest package
npm update uuid@latest
# update npm to check is everything updated
npm update
# Start and enable pm2 startup service and check the status
pm2 status
#Add variable homedir
homedir="$(getent passwd $( /usr/bin/id -u ) | cut -d: -f6)"
# Add variable user
user="$(getent passwd $( /usr/bin/id -u ) | cut -d: -f1)"
#Add PATH for pm2 and make a startup unit
sudo env PATH=$PATH:/$homedir/.nvm/versions/node/v16.13.2/bin /$homedir/.nvm/versions/node/v16.13.2/lib/node_modules/pm2/bin/pm2 startup systemd -u $user --hp $homedir
#start the pm2 service
sudo systemctl start pm2-pi.service
#enable the pm2 service during boot
sudo systemctl enable pm2-pi.service
#Install development tools
#To be able to compile and install native add-ons from the npm registry you need to install the development tools:
sudo apt install build-essential
# recommended reboot after the installation
sudo reboot