You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统下Cordova安装及NPM路径设置

Moving Global npm Packages (Including Cordova) to a Non-C Drive

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:

  1. Open System Properties (right-click This PC > Properties > Advanced system settings)
  2. Navigate to the Environment Variables section
  3. Under User Variables:
    • Find the Path variable, edit it, and replace the old npm path (C:\Users{yourName}\AppData\Roaming\npm) with your new D:\npm-global path
    • Add a new variable called NODE_PATH with the value D:\npm-global\node_modules (this helps Node.js locate global modules)
  4. 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 -v should return the version number (no errors means it’s functioning)
  • npm list -g cordova should show the package installed under D:\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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:52:23