Introduction
This guide covers how to install Node.js, npm, and PM2 on a Linux server — the standard toolchain for running JavaScript applications outside the browser, plus a process manager to keep them running reliably.
Node.js runs JavaScript on the server. npm (Node Package Manager) comes bundled with it and installs JavaScript packages. PM2 is a process manager that keeps your Node application running in the background, automatically restarts it if it crashes, and can bring it back up after a server reboot.
Implementation
I. Prerequisites
Before you install Node.js, npm, and PM2, make sure you have:
- A Linux server with root or sudo access
wgetandtaravailable (installed by default on most distributions)- Your application’s code ready to deploy, if you plan to run it immediately after setup
II. Download and Extract Node.js
cd /opt wget https://nodejs.org/dist/v20.17.0/node-v20.17.0-linux-x64.tar.gz tar -xvf node-v20.17.0-linux-x64.tar.gz
Note: Always check the official Node.js downloads page for the current LTS version rather than reusing an old, hardcoded version number — Node.js releases regular security updates, and versions from several years back (like v6.x) have long since reached end-of-life and no longer receive patches.
III. Create Symlinks
Link the extracted binaries into /usr/bin so node and npm are available system-wide:
ln -sf /opt/node-v20.17.0-linux-x64/bin/node /usr/bin/node ln -sf /opt/node-v20.17.0-linux-x64/bin/npm /usr/bin/npm
Double-check the path is
/usr/bin, not/use/bin— a one-character typo here is an easy mistake to carry over from a quick copy-paste, and it silently creates the symlink in a directory that doesn’t exist rather than throwing an obvious error.
IV. Verify the Installation
node -v npm -v
Both should print version numbers matching what you downloaded, confirming the symlinks resolved correctly.
V. Install PM2 Globally
npm install -g pm2
VI. Start Your Application with PM2
pm2 start app.js --name my-app
Replace app.js with your application’s entry file. The --name flag gives the process a readable label in PM2’s process list.
VII. Ensure PM2 Survives a Server Reboot
This step is easy to miss, and without it, your application won’t automatically come back up if the server restarts:
pm2 startup pm2 save
pm2 startup generates and configures a system service so PM2 itself starts on boot; pm2 save saves your current list of running processes so they’re restored automatically.
VIII. Useful PM2 Commands
pm2 list # Show all running processes pm2 logs my-app # View logs for a specific app pm2 restart my-app pm2 stop my-app
IX. Conclusion
Installing Node.js, npm, and PM2 comes down to downloading a current LTS release, linking the binaries system-wide, and letting PM2 handle keeping your application running — including automatically restarting it after crashes or a server reboot. With pm2 startup and pm2 save configured, your Node application stays running reliably without needing manual intervention every time the server restarts.
Frequently Asked Questions
Should I use this manual method or a version manager like nvm? For a single application on a dedicated server, this manual approach works fine. If you need to switch between multiple Node.js versions (for different projects or testing compatibility), nvm is generally more convenient, since it manages multiple installed versions without manual symlinking.
Why use PM2 instead of just running node app.js directly? Running Node directly stops the moment you close your terminal session or the process crashes. PM2 keeps it running in the background, restarts it automatically on a crash, and can bring it back up after a reboot — none of which a plain node app.js command provides on its own.
Do I need to update Node.js periodically? Yes — like any server software, Node.js receives security patches, and older versions eventually reach end-of-life with no further updates. Check the Node.js release schedule periodically and plan upgrades accordingly.
Talk to Our Technology Experts
Deploying and managing Node.js applications in production? Our team can help with server setup, process management, deployment pipelines, and ongoing infrastructure support.
Connect with our technology experts.