Install Node.js - I installed version 16.x
Create a new user to run n8n then login as that user
adduser --disabled-password n8n
su - n8n
Create a hidden directory for Node.js
mkdir ~/.nodejs_global
Set the NPM prefix to the new directory
npm config set prefix ~/.nodejs_global
Modify the user environment PATH to include the new directory
echo 'export PATH=~/.nodejs_global/bin:$PATH' >> ~/.profile
Active the new env config
source ~/.profile
Use npm to install n8n
npm install n8n --location=global
Install pm2 to manage the n8n service
npm install pm2@latest --location=global
Start, enable, and save n8n via pm2. You should be prompted here to setup systemd and run another command.
pm2 start n8n
pm2 startup
pm2 save
I reboot my server at this point to clear out anything that pm2 was doing and let systemd handle everything (which still uses pm2) going forward. I also changed the name of the systemd n8n file from pm2-n8n.service
to n8n.service
.