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

[Question] Maintaining global packages after installing new nodejs version #800

Closed
hongz1 opened this issue Apr 8, 2024 · 2 comments
Closed

Comments

@hongz1
Copy link

hongz1 commented Apr 8, 2024

I am new to use this package and looking for the best efficient way to maintain existing global packages installed.

[Original state before installing n]
my current node version is 18.17.1 and pm2 global package is installed in /usr/lib/node_modules already in Ubuntu (22.04).

[After installing n package with node version 20]
pm2 package is not showing in the global package list, but I can still run pm2.

Q1: Does it have global package migrations feature?

Q2: (if not) Should I uninstall existing global packages and reinstall them after installing new node version via 'n'?

I am not sure the best approach to manage existing global packages....

Thanks.

@shadowspawn
Copy link
Collaborator

A1: n does not have a global package migrations feature. n installs to a single prefix so you don't need to reinstall global packages when switching node versions using n.

A2: I think uninstalling the global packages from the old location is sensible so you don't have the ongoing confusion of packages installed in two locations.

You can do this without needing to reinstall node and npm by specifying the prefix explicitly, which you worked out is /usr for your old install. Doing one package at a time and not trying a fancy all-at-once...

# check what is installed in old location so can reinstall as needed
$ npm --prefix=/usr list -g  

# delete pm2 from old location
$ npm --prefix=/usr uninstall -g pm2

# check prefix is pointing at expected /usr/local before reinstalling
$ npm prefix -g
/usr/local

# check what is currently installed
$ npm list -g

# install pm2 if needed
$ npm install -g pm2

@hongz1
Copy link
Author

hongz1 commented Apr 9, 2024

Thank you.

@hongz1 hongz1 closed this as completed Apr 9, 2024
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

2 participants