Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make existing processes use new version of Node? #4430

Closed
vicatcu opened this issue Sep 25, 2019 · 4 comments
Closed

How to make existing processes use new version of Node? #4430

vicatcu opened this issue Sep 25, 2019 · 4 comments

Comments

@vicatcu
Copy link

vicatcu commented Sep 25, 2019

What's going wrong?

I have an existing set of process running in pm2 using NVM and Node 8.
I do the following set of steps to update my situation to Node 10.

pm2 unstartup
nvm install 10 --reinstall-packages-from=8
nvm alias default 10
# start a new terminal session
pm2 update
pm2 updatePM2
pm2 startup
pm2 status
pm2 info some-process

I feel like that should be enough to express my intent. And indeed it mostly seems to do the trick. However, the output of pm2 info some-process still indicates node.js version: 8.9.4, and the PATH environment variable reported there also clearly includes the NVM directory for node 8.9.4 binaries.

Obviously, I can pm2 delete some-process, and then re-do the pm2 start ... --name some-process incantation that I did in the first place, but I have to believe that there is some way for me to ask PM2 nicely to do this for me with a CLI command. Am I right?

How could we reproduce this issue?

  • Install NVM and Node 8
  • Install PM2 globally
  • pm2 start nodejs script
  • Use NVM to install Node 10 as described above.
  • Update PM2 as described above
  • Observe that the nodejs process you previously started has not switched to using Node 10

Supporting information

pm2 doesn't say anything useful, indicates Node 10 is in use everywhere.

@vicatcu
Copy link
Author

vicatcu commented Oct 9, 2019

Hi folks, hoping to migrate from Node 8 to Node 10, anyone care to comment?

@Unitech
Copy link
Owner

Unitech commented Oct 15, 2019

You can try pm2 restart app --update-env, it would override the env $PATH variable with the new Node.js path.

@Unitech Unitech closed this as completed Oct 15, 2019
@shlomisas
Copy link

@vicatcu , any solution?

@hyunbinseo
Copy link

hyunbinseo commented Oct 24, 2023

tl;dr

If you are managing the Node.js versions using Volta:

# Apps Only
volta install node@lts
volta install pnpm@latest
pm2 update

If you are managing the Node.js versions using pnpm:

# Apps Only
pm2 update

# Apps and Daemon
pm2 kill
pnpm env use latest -g # Change the active Node.js version
pnpm add pm2@latest -g # Reinstall the PM2 package globally
pm2

Apps Only

It is likely that the pm2 daemon is the one running on io.js 3.3.0. Try pm2 update in command line and refresh the dashboard. — keymetrics/pm2-plus-tech-questions#88

Reproduction using pnpm works as expected.

node -v # v20.8.1
&& pm2 start index.js --no-autorestart
&& pm2 info 0 # node.js version 20.8.1
&& pnpm env use latest --global
&& node -v # v21.0.0
&& pm2 update # >>>>>>>>>> PM2 updated
&& pm2 info 0 # node.js version 21.0.0
// index.js
console.log(new Date().toISOString());
console.log(process.version);
setInterval(() => {}, 60 * 1000);
~/.pm2/logs/index-out.log last 15 lines:
0|index    | 2023-10-24T02:28:10.818Z
0|index    | v20.8.1
0|index    | 2023-10-24T02:28:11.929Z
0|index    | v21.0.0

Apps and Daemon

pm2 update does not update the Node.js version used by the PM2 daemon.

# Reference ~/.pm2/pm2.log to check which Node.js version is used.

rm -rf ~/.pm2

# Use Node.js 20.10.0
pnpm env use lts --global
pm2 # 20.10.0 is used
pm2 kill

# Use Node.js 21.2.0
pnpm env use latest --global
pm2 # 21.2.0 is used
~/.pm2/pm2.log

2023-11-29T11:48:10: PM2 log: ========================================================
2023-11-29T11:48:10: PM2 log: --- New PM2 Daemon started -----------------------------
2023-11-29T11:48:10: PM2 log: Time                 : Wed Nov 29 2023 11:48:10 GMT+0000
2023-11-29T11:48:10: PM2 log: PM2 version          : 5.3.0
2023-11-29T11:48:10: PM2 log: Node.js version      : 20.10.0
2023-11-29T11:48:10: PM2 log: ========================================================
2023-11-29T11:48:10: PM2 log: PM2 successfully stopped
2023-11-29T11:48:48: PM2 log: ========================================================
2023-11-29T11:48:48: PM2 log: --- New PM2 Daemon started -----------------------------
2023-11-29T11:48:48: PM2 log: Time                 : Wed Nov 29 2023 11:48:48 GMT+0000
2023-11-29T11:48:48: PM2 log: PM2 version          : 5.3.0
2023-11-29T11:48:48: PM2 log: Node.js version      : 21.2.0
2023-11-29T11:48:48: PM2 log: ========================================================
2023-11-29T11:48:48: PM2 log: PM2 successfully stopped

pnpm users should reinstall PM2 globally after switching the Node.js version.

# This error occurs if the original Node.js version is uninstalled.

pm2
# /Users/~/Library/pnpm/pm2: line 13:
# /Users/~/Library/pnpm/nodejs/20.10.0/bin/node: No such file or directory
# Reference ~/.pm2/pm2.log to check which Node.js version is used.

rm -rf ~/.pm2

# Use Node.js 20.10.0
pnpm env use lts --global
pnpm add pm2@latest -g # IMPORTANT
pm2 # 20.10.0 is used
pm2 kill

# Use Node.js 21.2.0
pnpm env use latest --global
pnpm add pm2@latest -g # IMPORTANT
pm2 # 21.2.0 is used
pm2 kill

# Remove Node.js 20.10.0
pnpm env rm lts --global
pm2 # Works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants