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

Mac下使用npm安装Cordova与Ionic时遭遇权限错误求助

Hey there! Let's work through this problem together—you're totally right that this is a permission issue, and we've got a couple of solid ways to fix it.

Fixing npm Permission Errors When Installing Cordova/Ionic on Mac

What's Causing the Error?

The EACCES error happens because your regular user account doesn't have write access to the /usr/local/lib/node_modules directory. npm needs this access to install global packages like Cordova and Ionic, so it's blocked by macOS's security settings.

This is the safer approach because it avoids messing with system-level directories or using sudo (which can cause permission headaches later):

  • First, create a folder in your user directory to store global npm packages:
    mkdir ~/.npm-global
    
  • Tell npm to use this new folder as its global prefix:
    npm config set prefix '~/.npm-global'
    
  • Update your shell configuration to recognize the new package location:
    • If you use Bash, open ~/.bash_profile in a text editor and add this line:
      export PATH=~/.npm-global/bin:$PATH
      
    • If you use Zsh (the default on newer Macs), edit ~/.zshrc instead and add the same line.
  • Make the changes take effect immediately:
    source ~/.bash_profile  # For Bash users
    # OR
    source ~/.zshrc         # For Zsh users
    
  • Now you can install Cordova and Ionic without permission issues:
    npm install -g cordova ionic
    

Option 2: Change Ownership of the System Directory

If you prefer to modify the existing system directory instead, you'll need to use sudo—but first, note that the password you need to enter is your Mac's administrator password (the same one you use to log into your computer). When you type it in Terminal, you won't see any characters appear (this is normal security behavior)—just type it and press Enter.

Run this command to take ownership of the node_modules directory:

sudo chown -R $USER:$GROUP /usr/local/lib/node_modules

Once that's done, run your original install command again:

npm install -g cordova ionic

Quick Note About the sudo Password

If your password isn't working, double-check that you're using your current user's login password. If that still fails, go to System Settings > Users & Groups to confirm your account has administrator privileges.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:33:25