'NVM global module folder
I am using NVM and I am trying to install global NPM modules. That action requires permissions to a folder that I don't have permissions to. With regular node.js/npm that was easy to solve with prefix
configuration but NVM explicitly forbids it.
What is the right way to change the path to global modules folder in NVM?
Solution 1:[1]
To see the location of the current version of node you are using:
nvm which current
You are using the system installation if .nvm is not in the path, similar to the following:
/usr/local/bin/node
To switch to a version managed by nvm:
nvm use 4
To verify you are using a version managed by nvm:
nvm which current
You should see something similar to the following:
/Users/<your-user-name>/.nvm/versions/node/v4.2.2/bin/node
You should only experience global install permission issues when you are using the system installation.
Solution 2:[2]
As of 2022, there is no need to change the path to global modules folder over permissions,
as with active nvm
node global modules are installed under specific version of node.
Try
$nvm install 16
...
$nvm version > .nvmrc
$ which npm
/Users/user/.nvm/versions/node/v16.14.2/bin/npm
$ which node
/Users/user/.nvm/versions/node/v16.14.2/bin/node
npm global install e.g. npm install -g @angular/cli
will install into/Users/user/.nvm/versions/node/v16.14.2/lib/node_modules
Remember to nvm use
to get back from .nvmrc
to exact node version for which those global modules were installed.
npm list -g --depth=0
to list installed global modules
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |