Node Modules Global installs on Unix systems go to {prefix}/lib/node_modules . Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)
prefix Configuration The prefix config defaults to the location where node is installed. On most systems, this is /usr/local . On Windows, it's %AppData%\npm .
Everything you need is in the npm-folders
documentation. I don't want to start my Win notebook now so I cannot verify it, but you should only change prefix
to C:\Program Files\nodejs
in your config file. If you want to change it globally for all users, edit the C:\Program Files\nodejs\npmrc
file, otherwise create/edit C:\Users\{username}\.npmrc
.
But this change will probably have some side effects, so read this discussion first. I don't think it's a good idea.
trying to install global packages into C:\Program Files (x86)\nodejs\
gave me Run as Administrator issues, because npm was trying to install intoC:\Program Files (x86)\nodejs\node_modules\
to resolve this, change global install directory to C:\Users\{username}\AppData\Roaming\npm
:
in C:\Users\{username}\
, create .npmrc
file with contents:
prefix = "C:\\Users\\{username}\\AppData\\Roaming\\npm"
reference
npm install -g package
installs global packages into prefix location
npm config ls -l
was showing prefix = "C:\\Program Files (x86)\\nodejs"
environment
nodejs x86 installer into C:\Program Files (x86)\nodejs\
on Windows 7 Ultimate N 64-bit SP1node --version
: v0.10.28npm --version
: 1.4.10
You can see my answer to this in my answer to another question.
In Windows, the global install path is actually in your user's profile directory
%USERPROFILE%\AppData\Roaming\npm
%USERPROFILE%\AppData\Roaming\npm-cache
npm install
as that user. Some modules/utilities should be installed globally....\npm
directory to your users path yourself.To change the "global" location for all users to a more appropriate shared global location %ALLUSERSPROFILE%\(npm|npm-cache)
(do this as an administrator):
[NODE_INSTALL_PATH]\etc\
directory
npm config --global ...
actionsC:\ProgramData\npm-cache
- npm modules will go hereC:\ProgramData\npm
- binary scripts for globally installed modules will go hereC:\ProgramData\npm\node_modules
- globally installed modules will go herenpm config --global set prefix "C:\ProgramData\npm"
npm config --global set cache "C:\ProgramData\npm-cache"
C:\ProgramData\npm
to your System's Path environment variable If you want to change your user's "global" location to %LOCALAPPDATA%\(npm|npm-cache)
path instead:
C:\Users\YOURNAME\AppData\Local\npm-cache
- npm modules will go hereC:\Users\YOURNAME\AppData\Local\npm
- binary scripts for installed modules will go hereC:\Users\YOURNAME\AppData\Local\npm\node_modules
- globally installed modules will go herenpm config set prefix "C:\Users\YOURNAME\AppData\Local\npm"
npm config set cache "C:\Users\YOURNAME\AppData\Local\npm-cache"
PATH
.
setx PATH "%PATH%;C:\Users\YOURNAME\AppData\Local\npm"
Building on the installation concept of chocolatey
and the idea suggested by @Tracker, what worked for me was to do the following and all users on windows were then happy working with nodejs
and npm
.
Choose C:\ProgramData\nodejs
as installation directory for nodejs
and install nodejs
with any user that is a member of the administrator group.
This can be done with chocolatey as: choco install nodejs.install -ia "'INSTALLDIR=C:\ProgramData\nodejs'"
Then create a folder called npm-cache
at the root of the installation directory, which after following above would be C:\ProgramData\nodejs\npm-cache
.
Create a folder called etc
at the root of the installation directory, which after following above would be C:\ProgramData\nodejs\etc
.
Set NODE
environment variable as C:\ProgramData\nodejs
.
Set NODE_PATH
environment variable as C:\ProgramData\nodejs\node_modules
.
Ensure %NODE%
environment variable previously created above is added (or its path) is added to %PATH%
environment variable.
Edit %NODE_PATH%\npm\npmrc
with the following content prefix=C:\ProgramData\nodejs
From command prompt, set the global config like so...
npm config --global set prefix "C:\ProgramData\nodejs"
npm config --global set cache "C:\ProgramData\nodejs\npm-cache"
It is important the steps above are carried out preferably in sequence and before updating npm (npm -g install npm@latest
) or attempting to install any npm
module.
Performing the above steps helped us running nodejs
as system wide installation, easily available to all users with proper permissions. Each user can then run node
and npm
as required.
You should use this command to set the global installation flocation of npm packages
(git bash) npm config --global set prefix </path/you/want/to/use>/npm
(cmd/git-cmd) npm config --global set prefix <drive:\path\you\want\to\use>\npm
You may also consider the npm-cache
location right next to it. (as would be in a normal nodejs installation on windows)
(git bash) npm config --global set cache </path/you/want/to/use>/npm-cache
(cmd/git-cmd) npm config --global set cache <drive:\path\you\want\to\use>\npm-cache
Step 1:
npm config get prefix
- Default Path is :
%USERPROFILE%\AppData\Roaming\npm
Step 2:
npm config get cache
- Default Path is :
%USERPROFILE%\AppData\Roaming\npm-cache
Step 3:
npm config set prefix \npm
- example
npm config set prefix C:\\dev\\node\\npm
Step 4:
npm config set cache \npm-cache
- example
npm config set cache C:\\dev\\node\\npm-cache
Run steps 1 & 2 again to check whether the paths are updated as required
That's it. Whenever you install global packages you should see them installed inside \npm\node_modules
The default global folder is C:\Users\{username}\AppData\Roaming\npm
.
You can create (if it doesn't exist) a .npmrc
file in C:\Users\{username}\
and add
prefix = "path\\to\\yourglobalfolder"
.
Note that, in windows, the path should be separated by double back-slash
.
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