In this tutorial, I will help you to fix the pm2: command not found error the easiest way.
In short, the pm2: command not found error occurs because the pm2 package is not recognized by the terminal, which means it is not installed yet, or not installed globally.
So the solution is to install it using
sudo npm install -g pm2 or
sudo yarn global add pm2.
To understand more, you can read the content below.
Table of Contents
In case you are following some tutorials on the Internet and don't know what pm2 is, let me explain it to you.
pm2 is a process manager for Node.js applications. It helps you to:
- Run an application and keep it alive.
- Reload application without downtime.
- Perform common sys-admin tasks.
For my use case, I usually use pm2 to run my NextJs application in a VPS hosted on DigitalOcean.
The most popular reason why you encounter the pm2: command not found error is that the pm2 package is not installed, or not installed GLOBALLY.
Thus, the terminal cannot recognize the
pm2 command, and it throws back the error
pm2: command not found.
To fix the pm2: command not found error, you will need to install the pm2 package globally.
You can open your Terminal (in Linux or MacOS), and run one the following commands to install the pm2 package globally:
- If you use
npm(or no idea what you are using), run:shell
- If you use
This command uses the
yarn) package manager to install the
pm2 package globally. So make sure
npm is also installed. If not, it might throws back the error
npm: command not found and you will need to install Node.js first.
Cool, we installed the pm2 package globally now. Move to the next section to check if it's installed successfully.
To check if pm2 is installed successfully, run the following command:
If it returns the version of pm2, then you have installed pm2 successfully.
For example, at the time I write this post, the latest version of pm2 is
5.3.0, so it returns:
Node.js will provide us the
npm package manager, so we need to install Node.js.
To install Node.js, there are 2 ways:
It's easier to use the installer, just download and follow the instructions. So I won't write the instructions here.
I will try to cover the nvm way right below.
Follow these steps to install nvm on Linux/MacOS:
- Open Terminal.
- Run the following command:
I suggest you to visit the official guide to update the latest version. The version at the time I write this post is
- Close and reopen the Terminal. Now you can install Node.js using nvm.
- Open Terminal.
nvm install latestto install the latest version of Node.js.
nvm use latestto use the latest version of Node.js.
sudo npm install -g pm2to install pm2 globally.
That's all, now you have installed Node.js and pm2 successfully on Linux/MacOS.
To recap, you can fix the pm2: command not found error by installing the pm2 package globally using
npm install -g pm2 or
yarn global add pm2.
In case you don't have Node.js on your machine, I also added the instructions to install Node.js using the official installer and nvm.
Thanks for reading! Please comment below if you need any more assistance.