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

Windows环境下Angular 2-4无法运行的CLI安装故障求助

Fixing Angular CLI Issues After Windows 7 Update

Hey there, let's work through this problem step by step—Windows updates love to mess with permissions and environment paths, which is almost certainly what's going on here.

Step 1: Fix Permission Errors First

The EPERM error and "run as administrator" hint tells us we need elevated privileges to fix the CLI installation. Here's what to do:

  • Open Command Prompt as Administrator: Right-click the Command Prompt icon and select Run as administrator (this is non-negotiable for modifying global npm packages on Windows 7).
  • Uninstall the broken global Angular CLI installation:
    npm uninstall -g @angular/cli
    
  • Clear npm's cache to get rid of corrupted files:
    npm cache clean --force
    
  • Manually delete any leftover @angular/cli folder: Navigate to C:\Users\<Your Username>\AppData\Roaming\npm\node_modules and delete the @angular/cli directory if it's still there (the error about renaming means this folder was locked or corrupted).

Step 2: Reinstall Angular CLI Globally

With the old installation cleaned up, reinstall the latest CLI with admin rights:

npm install -g @angular/cli@latest

This should run without EPERM errors now that you're using an admin prompt and cleared the cache.

Step 3: Fix the "ng is not recognized" Error

This happens when Windows can't find the ng executable in your system's PATH. Let's fix that:

  • Locate npm's global bin folder: It's usually at C:\Users\<Your Username>\AppData\Roaming\npm (this is where ng.cmd gets installed).
  • Add this path to your system environment variables:
    1. Right-click Computer → Properties → Advanced System Settings → Environment Variables.
    2. Under System Variables, find the Path variable, click Edit.
    3. Add the npm bin folder path (e.g., C:\Users\JohnDoe\AppData\Roaming\npm) to the list.
  • Restart Command Prompt (environment changes won't take effect until you do this).
  • Test if ng works by running:
    ng --version
    

Step 4: Correct Your Project Setup Command

Quick note: npm install ng serve is not a valid command—this is why it didn't work. For your Angular project:

  1. Navigate to your project folder in Command Prompt (you don't need admin rights for this part).
  2. Install project dependencies first:
    npm install
    
  3. Then start the development server:
    ng serve
    

Step 5: Verify Project Folder Permissions

Since you mentioned node_modules permissions issues, double-check your project folder's access rights:

  • Right-click your project folder → Properties → Security.
  • Make sure your user account has Full Control permissions for the folder (and all subfolders like node_modules). If not, click Edit to add or adjust these permissions.

After following these steps, your Angular CLI should work just like it did before the Windows update!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:21:15