Everything you need is adjust parameters of
prefix
*, cache
, and tmp
in a config file. Now we want to change it globally for all users on the same machine.* Determined where all global packages saved.
There are two methods to solve this.
1
Go to Node.js root directory, normally it is
C:\Program Files\Nodejs\
. Create a new folder and name it etc
.Create/go to a directory where you wish NPM's all packages placed. In this post, I assume that this place is
F:\Misc\Sample\
.Copy the followings and paste into an editor (notepad, sublime text, etc.):
cache=F:\Misc\Demo\npm-cache
prefix=F:\Misc\Demo\npm
tmp=F:\Misc\Demo\npm-temp
!Note: remember to change my example directories by yours.
Then save it to
etc
folder under the name of npmrc
.Now we are going to update NPM's path. Open Windows Explorer or press
Windows + E
on keyboard, paste the below row in navigation bar then press Enter
:Control Panel\All Control Panel Items\System
Look at left sidebar of "System" window, find and click on "Advanced system settings" to open "System Properties" box.
Click on "Environment Variables" button at the bottom to open "Environment Variables" box.
In the table of "System variables", double clicks on "Path" row, and add a new variable.
Import an NPM's directory (in the example, it is
F:\Program\Nodejs\npm
) into blank field.Then we verify NPM's location, open command promt and type:
where npm
The result should be:
F:\Misc\Demo\npm
F:\Misc\Demo\npm.cmd
2
Open command promt, create required folders:
mkdir "F:\Misc" "F:\Misc\Demo" "F:\Misc\Demo\npm-cache" "F:\Misc\Demo\npm" "F:\Misc\Demo\npm-temp"
Apply changes to NPM's config file:
npm config --global set cache "F:\Misc\Demo\npm-cache"
npm config --global set prefix "F:\Misc\Demo\npm"
npm config --global set tmp "F:\Misc\Demo\npm-temp"
NPM will create a
npmrc
file saved to etc
folder in nodejs's root directory. The flag --global
means changes applied to all users.If the flag is ignored, another file called
.npmrc
can be found in user's home directory (for quickly access, in terminal, type: %homepath%
).The file's content should be:
cache=F:\Misc\Demo\npm-cache
prefix=F:\Misc\Demo\npm
tmp=F:\Misc\Demo\npm-temp
Repeat the last step as said in method 1, update and verify NPM's path:
set path="F:\Misc\Demo" /m
where npm
Every configurable attribute of NPM can be set in order of priority:
- Environment variables:
NPM_CONFIG_PREFIX={Node.js directory}\node_modules
- User config file:
%homepath%/.npmrc
- Global config file:
{Node.js root directory}/etc/npmrc
Enjoy!
Post a Comment