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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With