title: How do you use pm2 startup with a non-root user?
body: <p>According to the documentation here: <a href="http://pm2.keymetrics.io/docs/usage/startup/#startup-systems-support" rel="noreferrer">http://pm2.keymetrics.io/docs/usage/startup/#startup-systems-support</a></p>
  
  <p>You can use the command <code>pm2 startup ubuntu -u nodeapps</code> to resurrect all saved pm2 jobs on server startup.</p>
  
  <p>I ran this command as the nodeapps user. Then I was given a sudo su command to run. I logged out of nodeapps, used sudo su to log into the system as root, and ran the command:</p>
  
  <pre><code>sudo su -c "env PATH=$PATH:/usr/bin pm2 startup ubuntu -u nodapps --hp /home/nodeapps"
  </code></pre>
  
  <p>The processes did not restart on server restart. I found this question on Stack Overflow: <a href="https://stackoverflow.com/questions/32769302/ubuntu-14-04-pm2-startup-not-starting-after-reboot">Ubuntu 14.04 - pm2 startup not starting after reboot</a>.</p>
  
  <p>In the script <code>/etc/init.d/pm2-init.sh</code> I found the line that question recommended addressing:</p>
  
  <pre><code>export PATH=/usr/bin:$PATH
  export PM2_HOME="/home/nodeapps/.pm2"
  </code></pre>
  
  <p>But it looks correct to me so I didn't change anything.</p>
  
  <p>I then found this question: <a href="https://stackoverflow.com/questions/34821063/pm2-startup-not-starting-up-on-ubuntu">pm2 Startup not starting up on Ubuntu</a></p>
  
  <p>and in my boot logs I find the following line:</p>
  
  <pre><code>Starting pm2
  /usr/bin/env: node: No such file or directory
  </code></pre>
  
  <p>I know that 'node' on Ubuntu is actually 'nodejs'. Could this be the reason?</p>
  
  <p>If it is, what can I do to make the startup command look for nodejs instead of node. </p>
  
  <p>Alternatively, could this be a $PATH problem? If it is, how can I add the correct path to root (at least I think it should be added to root)</p>