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

Windows 10下配置npm环境变量及私有仓库Token的方法咨询

Hey there! Let's tackle your two npm configuration questions for Windows step by step, since Unix-style commands don't work directly on Windows systems.

1. 配置Windows系统的npm环境变量

First off, npm usually gets installed alongside Node.js, so we just need to make sure its path is added to your system's environment variables:

  • Find npm's installation path:
    • The default user-specific path is C:\Users\<YourUsername>\AppData\Roaming\npm (replace <YourUsername> with your actual Windows username)
    • If you installed Node.js globally, it might also be in C:\Program Files\nodejs (since npm lives here too)
  • Open Environment Variables settings:
    • Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
    • Or press Win+R, type sysdm.cpl, hit Enter, then switch to the "Advanced" tab and click "Environment Variables"
  • Edit the Path variable:
    • Under "System Variables", find Path and click "Edit"
    • Click "New" and paste the npm path you found earlier, then save all changes
  • Verify it works: Open a new Command Prompt or PowerShell window, type npm -v — if it shows your npm version, you're good to go!
2. 在Windows 10中配置NPM_TOKEN以拉取私有包

The export command you saw in the npm docs is for Unix-based systems (Linux/macOS). On Windows, we have two ways to set this token: temporarily for the current session, or permanently for all future sessions.

临时生效(仅当前窗口可用)

  • Command Prompt (cmd):
    Run this command, replacing the placeholder with your actual hex token:
    set NPM_TOKEN="00000000-0000-0000-0000-000000000000"
    
  • PowerShell:
    Use this syntax instead:
    $env:NPM_TOKEN="00000000-0000-0000-0000-000000000000"
    

永久生效(所有新窗口自动加载)

We recommend either of these two methods for long-term use:

Method 1: Set via System Environment Variables

  • Go back to the Environment Variables settings (same steps as before)
  • Under "User Variables" (for just your account) or "System Variables" (for all users), click "New"
  • Set Variable name to NPM_TOKEN and Variable value to your hex token, then save
  • Restart your Command Prompt/PowerShell, then verify with:
    • cmd: echo %NPM_TOKEN%
    • PowerShell: echo $env:NPM_TOKEN

Method 2: Configure the .npmrc file (npm's preferred way)

This is better because it's tied directly to npm's configuration, avoiding any system-wide environment variable conflicts:

  • Navigate to your user directory: C:\Users\<YourUsername>
  • Look for a file named .npmrc — if it doesn't exist, create a new text file and rename it to .npmrc (make sure to remove the .txt extension)
  • Open .npmrc in a text editor and add this line, replacing the registry URL and token with your team's details:
    //your-private-registry-url/:_authToken=00000000-0000-0000-0000-000000000000
    
    Note: Replace //your-private-registry-url/ with your team's actual private npm registry address (e.g., //npm.yourcompany.com/). If you're unsure, ask your team for the correct registry URL!
  • Save the file, then try running npm install for your project — it should automatically use the token to pull private packages.

内容的提问来源于stack exchange,提问作者Abhijit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:43:43