I am trying to install pm2 logrotate on ubuntu server. I run the command
pm2 install pm2-logrotate
I get the following error
[PM2][Module][ERROR] Unknown module
Any ideas on what could be wrong?
Related
Mac os Catalina 10.15.5 / npm version 6.14.5
When I install pm2, it seems that it is being installed without any problem.
But if I run pm2, the terminal only says that command not found.
It's not working at all. It just doesn't start.
I searched through StackOverflow and tried the following solutions.
- npm i -g pm2
- sudo npm install -g pm2
- npm i pm2#latest --no-optional -g --no-shrinkwrap
- sudo npm install pm2 -g --unsafe-perm
All of the above gives me this result.
/Users/myname/.npm-global/bin/pm2 -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2
/Users/myname/.npm-global/bin/pm2-docker -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-docker
/Users/myname/.npm-global/bin/pm2-dev -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-dev
/Users/myname/.npm-global/bin/pm2-runtime -> /Users/myname/.npm-global/lib/node_modules/pm2/bin/pm2-runtime
+ pm2#4.4.0
updated 1 package in 4.768s
After this,
If I type pm2 : I get pm2-bash: pm2: command not found
If I type whereis pm2 : it just doesn't do anything at all.
If I type pm2 start index.js in VScode terminal: zsh: command not found: pm2
And there are the files inside of the path(/Users/myname/.npm-global/bin/).
I don't know what the problem is.
Any help or advice will be appreciated.
those who are having the same problem, hope it helps.
After repeating countless uninstall & install of node/npm/pm2 whatsoever and toying around the permissions, I found answer by myself.
Changed default command shell from zsh to bash. (in VScode as well)***
Deleted all the node & npm and installed nvm, and re-installed node via nvm.(npm is automatically installed together).
Installed pm2 with npm.
I recently cloned my nodejs express app on ec2 ubuntu instance. I ran npm install pm2 but it didn't have write permissions. So I ran
sudo chown _R $USER /usr/lib/node_modules
After that PM2 got installed but when I hit pm2 start app.js, it shows pm2 command not found. I have installed it globally locally but nothing works.
What should I do? Check out the screenshot of ERROR
pm2 needs to be installed globally (on the server) to function correctly.
Try
sudo npm install -g pm2
Digital Ocean has an excellent tutorial on this.
in your home directory
sudo npm install -g pm2
relogin to OR restart your instance
There is a simple way to solve it, just add the pm2 statement as a new script in your package.json file.
In your root project folder type
nano package.json
Then the package file opens and you can add the following line after the script line
"pm2 start src/<yourappname.js>"
your file should look like this
"scripts": {
"pm2": "pm2 starts src/<yourappname.js>"
}
Then press ctl + x and enter to save
(You ust replace src/<yourappname.js> for the path adn name of your js file, in my case I have a folder called src into my project root folder)
Lastly, just run the script by typing the following line
npm run pm2
and you got it.
I need to deploy a NodeJs application following this tutorial https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04.
When installing PM2 module and generating pm2 daemon script pm2 startup upstart, no command is shown, normally it should display a command like this:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy
NodeJs v0.10.48 (on Ubuntu-12)
I have installed pm2 module using the following command:
npm install pm2#latest
Then I tried to start my test application using pm2 as follows:
$ pm2 start test.js
It throws the following error:
'pm2' is not recognized as an internal or external command
Do i need to set environment variable for pm2?
You need to install PM2 globally via npm install --global pm2#latest and if you want to use the local version, try ./node_modules/.bin/pm2 start test.js.
After installing PM2, we may need to add following value to path variable under Environment Variables
C:\Users\USERNAME\AppData\Roaming\npm
After adding, reopen the command prompt.
You might installed the pm2 locally instead of global scope, this is due to missing -g parameter in your installation command.
npm install -g pm2
or
yan add -g pm2
If you tried npm install pm2 then the module will install locally to the app that you are currently developing from there you can invoke the pm2 using,
./node_modules/pm2/bin/pm2 start index.js
But it won't mostly work on windows. Try to use the global install option.
You are getting the same error after global install option then add the npm path in your environment variables.
After updating Node.js from v10.16 to v10.32, PM2 was not detected, however it was running fine when checked with ps aux. Even upon system reboot PM2 functioned correctly even though manual PM2 commands resulted in following type of error.
pm2 list
pm2: command not found
Switching Node.js back to 10.16 and PM2 commands were again available. fyi PM2 was initially installed under v10.16.
While in v10.32 tried PM2 install command npm install pm2 -g but had to use command npm install pm2 -g --unsafe-perm to get operational.
Node.js v10.16 now runs PM2 v10.1.
Node.js v10.32 now runs PM2 v10.8.
Is this the proper method to keep PM2 versions in sync and working with Node upgrades/changes? Does this need to occur after installing every new version of Node?
It's seem there no way without re-installing PM2 after a Node update :-(
$ nvm install 6.11.3 --reinstall-packages-from=6.11.2 && nvm alias default 6.11.3
$ nvm uninstall 6.11.2
$ pm2 update # Update in memory pm2
$ pm2 startup
$ nano /etc/init.d/pm2-init.sh # Wrong path :-(
But re-installing pm2 is not enought, some things are still broken even if it seem to work, logs are no more in real time for example
My hot fix :
$ rm -rf /root/.pm2
$ pm2 reload pm2.json --env production
$ pm2 startup ubuntu
Do not forget to rebuild packages after updating the version of node.js:
cd /to/root/of/your/project
npm rebuild
npm i -g pm2 && pm2 update
# here 0 and dist/main.js change for your project
pm2 delete 0 && pm2 start dist/main.js
In console :
pm2 save --First make sure that you saved correctly all your processes
npm install pm2 -g --Then install the latest PM2 version from NPM
pm2 update --And finally update the in-memory PM2 process
When you switch node versions, you also switch the packages, so you need to reinstall pm2 on node update. Fortunately this does not happen very often.
You could make a shell sript to do both in one go.
For the unsafe-perm thing, it comes only if you install pm2 as root. It makes sense when you think that pm2 has quite a lot of control over your machine's processes.
I tried a lot of times with differnent combinations but still seems not very stable and smart solution. Hence I am listing some of the logic I can think of something which may be you can apply and monitor the result as you upgrading and writing the scripts.
Basically in my situation we have a bunch of applications running under Node. So things getting complex when you need PM2 to launch anothe application that also installed under Node Version Managers, like NVM
Ex. I have
nvm ls
-> v14.17.6
PM2 is installed under:
which pm2
~/.nvm/versions/node/v14.17.6/bin/pm2
Since I am using App1 (a NodeJS app managed by npm). I got:
which App1
~/.nvm/versions/node/v14.17.6/bin/App1
So every time I upgrade using nvm:
nvm install --lts --reinstall-packages-from=14 --latest-npm
Then nvm using a newer version in this console. e.g. 14.7.999999
Perhapse I (at most of the time) needs to get my PM2 plus other applications upgrade at the same maintenance window, I use ncu, ncu -g and upgrade them.
Now, the applications end up with all new version. Ex. a new PM2 instance (local) and an old PM2 running (In Memory) with old comsumer applications (App1) in an old node folder. New version of App1 now exists in new Node application folder but not running.
In memory PM2 version: 5.1.0
Local PM2 version: 5.1.1
Anyway, if you don't have an upgraded version of PM2, you probably still looking for a new path of PM2 installed under your new Node folder. If not, you can install PM2 again with the upgraded node
npm i -g pm2
The thing getting worse is PM2 is in system startup scripts which needs to be re-written. Ex.
/etc/systemd/system/pm2-xx.service
So I endup with vanishing all applications:
pm2 stop app1 && pm2 delete app1
pm2 stop app2 (verdaccio json startup config) && pm2 delete app2
...
pm2 stop appN && pm2 delete appN
Then do:
pm2 update
To swap to the new PM2 instance
Then re-provision all the applications
pm2 start app1, app2, ... appN
Then do
pm2 update
To update the list of applications, check if correct Node path is used.
If all applciation paths are corrected
Do
pm2 startup systemd
And copy and run the suggested Startup Script
sudo env PATH=$PATH:/....
Finally run
pm2 save
To freeze the list on startup.