Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy global modules between Node installations using nvm?

Tags:

node.js

nvm

I manage my Node installations using nvm. I installed the grunt-cli module globally in my previous installation of node. This allowed me to run the command grunt on in the terminal.

When I installed a new version of Node (5.7.1), I got this error whenever I tried to execute the grunt command:

zsh: command not found: grunt

I discovered that the grunt-cli package had not been installed for the new version of Node.

I could install the grunt-cli package again but I would prefer to do this automatically whenever a new version of Node is installed using nvm.

Is there some way to install all the global modules from a previous version of Node when using nvm ?

like image 587
gnerkus Avatar asked Mar 03 '16 19:03

gnerkus


1 Answers

This can be achieved using the --reinstall-packages-from option when executing nvm install. From the nvm documentation:

If you want to install a new version of Node.js and migrate npm packages from a previous version:

nvm install node --reinstall-packages-from=node

This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.

If your prior version of Node is 4.3.0, the command will be executed thus:

nvm install v5.7.1 --reinstall-packages-from=4.3.0
like image 109
gnerkus Avatar answered Oct 12 '22 21:10

gnerkus