Reinstall global packages after updating node using NVM

Node Version Manager (nvm) is a tool I use on a daily basis. Lately, we have upgraded some projects to newer Node versions and this is causing some problems.

The problem

My global packages (like cdk) were installed when I was still running version 16. Now I'm running version 18 and those packages are not globally available anymore.

The same can happen when running nvm install upgrades Node to a new minor or patch version.

The solution

Next time this happens to you, follow these steps:

  • Run nvm list to find the previously installed version, the one that "contains" the global packages
  • Run nvm reinstall-packages <previousVersion> to get your global packages back.


If you want to get a list of all globally installed packages, run npm list -g --depth 0.

Comments (0)

Got a question? Liked the article or got a suggestion? Leave a comment to let us know.