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

Angular CLI安装报错errno -13(EACCES权限问题),求解决方法

Fixing EACCES Error When Installing Angular CLI

Hey Wei, that EACCES error is a super common hiccup when installing global npm packages—basically, your user account doesn’t have write permissions to the default global node_modules folder at /usr/local/lib/node_modules. Let’s walk through a few safe, practical fixes:

Option 1: Temporary Sudo Install (Quickest Short-Term Fix)

If you just need to get Angular CLI installed right away, you can run the command with elevated privileges:

sudo npm install -g @angular/cli

Just enter your system password when prompted. Note: Packages installed this way will require sudo for future updates, and might cause file permission quirks down the line.

This adjusts permissions so your regular user owns the directories npm needs to write to, eliminating the need for sudo entirely:

  1. First, confirm npm’s global prefix directory:
    npm config get prefix
    
    This should return /usr/local for your setup.
  2. Update the owner of the relevant subdirectories to your user:
    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
    
  3. Now you can run the original install command without issues:
    npm install -g @angular/cli
    

Option 3: Use a Custom Global npm Directory (Most Secure)

If you don’t want to modify system directory permissions, set up a dedicated global folder in your user directory:

  1. Create the custom directory:
    mkdir ~/.npm-global
    
  2. Configure npm to use this directory as its global prefix:
    npm config set prefix '~/.npm-global'
    
  3. Add the custom directory’s bin folder to your shell’s PATH (so your system can find globally installed tools like ng):
    • Open your shell config file (e.g., ~/.bashrc for Bash, ~/.zshrc for Zsh):
      nano ~/.bashrc
      
    • Add this line at the end:
      export PATH=~/.npm-global/bin:$PATH
      
    • Save and exit, then refresh the config:
      source ~/.bashrc
      
  4. Now install Angular CLI normally:
    npm install -g @angular/cli
    

Quick Side Note

Your Node.js version (v8.11.1) is quite outdated—newer versions of Angular CLI may not support it. If you run into additional errors after fixing permissions, consider upgrading Node.js to a supported LTS version (like 14.x or 16.x) to ensure full compatibility.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:30:23