Windows系统下Cordova安装及NPM路径设置
Hey there! I’ve walked plenty of developers through this exact setup—let’s get your global npm tools shifted off your C drive with straightforward, actionable steps:
Step 1: Create New Directories for Global npm Files
First, pick a location on your preferred drive (like D:) and make two folders:
D:\npm-global(this will store all your global packages)D:\npm-cache(this holds npm’s cache files to free up C drive space)
Step 2: Update npm’s Global Configuration
Open your command prompt (CMD or PowerShell) and run these commands to tell npm to use your new folders:
npm config set prefix "D:\npm-global" npm config set cache "D:\npm-cache"
Pro tip: You can double-check the changes anytime by running npm config get prefix and npm config get cache—they should show your new D:\ paths.
Step 3: Update Your System Environment Variables
This step ensures your system recognizes the new global package location:
- Open System Properties (right-click This PC > Properties > Advanced system settings)
- Navigate to the Environment Variables section
- Under User Variables:
- Find the
Pathvariable, edit it, and replace the old npm path (C:\Users{yourName}\AppData\Roaming\npm) with your newD:\npm-globalpath - Add a new variable called
NODE_PATHwith the valueD:\npm-global\node_modules(this helps Node.js locate global modules)
- Find the
- Click OK to save changes—you’ll need to restart your terminal (or even your PC) for these updates to take effect
Step 4: Reinstall Cordova (and Other Global Packages)
First, remove the existing Cordova from your old C drive location:
npm uninstall -g cordova
Then install it again—this time it will automatically go to your new D:\npm-global directory:
npm install -g cordova
If you have other global packages you want to move, repeat this uninstall/reinstall process for each one.
Step 5: Verify Everything Works
Run these commands to confirm your setup is working correctly:
cordova -vshould return the version number (no errors means it’s functioning)npm list -g cordovashould show the package installed underD:\npm-global\node_modules
Quick Notes
- If you get "command not found" errors after setup, double-check your Path variable and make sure you restarted your terminal/PC
- Manually moving existing package files from the old directory to the new one can cause broken dependencies, so reinstalling is the safest approach
内容的提问来源于stack exchange,提问作者Arvind Nagar

