Despite multiple attempts, I can't get PM2 to work on my macOS system. I've tried various methods like using sudo and adjusting npm directory permissions, but the 'pm2' command still isn't recognized.
Hi,
I'm currently trying to install PM2 globally.
1.
=> npm i pm2 -g
=>
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. ** Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
changed 163 packages in 9s
13 packages are looking for funding run npm fund for details
2. Here, I installed the latest version. It gave me the same error, so I installed version 7 following an article on Stack Overflow.
=> npm install [email protected] --force
=> npm i pm2 -g
Then, I encountered this error.
=>
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /Users/luc/.npm-global/lib/node_modules/pm2
npm ERR! dest /Users/luc/.npm-global/lib/node_modules/.pm2-5OKUrFlt
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 501:20 "/Users/luc/.npm"
npm ERR! A complete log of this run can be found in:
/Users/luc/.npm/_logs/2024-02-26T09_02_35_358Z-debug-0.log
3.
=> sudo chown -R 501:20 "/Users/luc/.npm"
=> sudo npm install pm2 -g
=>
d [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
changed 163 packages in 8s
13 packages are looking for funding run npm fund for details
In conclusion, despite several attempts to install PM2 on my macOS system, I continue to experience issues with the 'pm2' command not being recognized in the terminal. I've tried various approaches, including using sudo, modifying npm directory permissions, and reinstalling PM2, but the problem persists.
How can I resolve this issue effectively?
Therefore, I request your assistance in understanding and resolving this PM2 installation problem. Any suggestions or guidance would be greatly appreciated.
Thanks in advance!
I solved the problem
Cause :
I identified the source of my problem: version 21 of Node.js.
SOLUTION :
To resolve this, I first tried installing a version 20 of Node.js, but realized I didn't have NVM.
I installed NVM, here are the instructions: Formulae and NVM GitHub to install NVM.
Then, I upgraded node to version 20, here is the command:
After that, I verified that everything was working correctly by running:
I hope this explanation can be useful to someone.