Fixing npm ENOTEMPTY Installation Error | Generated by AI

Home 2025.10

Understanding the Error

Your sudo npm i -g @anthropic-ai/claude-code --verbose command is failing with an ENOTEMPTY error during the installation process. This is a common npm issue that occurs when npm tries to rename (or move) an existing directory as part of updating or reinstalling a package, but the directory isn’t empty. In this case, it’s specifically failing to rename /usr/lib/node_modules/@anthropic-ai/claude-code to a temporary backup location (/usr/lib/node_modules/@anthropic-ai/.claude-code-ZjqcDZyQ).

This typically happens due to:

The package itself (@anthropic-ai/claude-code) is legitimate—it’s Anthropic’s official CLI tool for “Claude Code,” an agentic coding assistant that integrates with your terminal and codebase.

Quick Fixes

Try these steps in order. Run them as root or with sudo where noted, since this is a global install.

  1. Manually Remove the Existing Directory
    This clears out the problematic partial install:
    sudo rm -rf /usr/lib/node_modules/@anthropic-ai/claude-code
    
    • If the parent scoped directory (@anthropic-ai) is now empty, you can remove it too:
      sudo rm -rf /usr/lib/node_modules/@anthropic-ai
      

      Then retry your original command:

      sudo npm i -g @anthropic-ai/claude-code --verbose
      
  2. Clear npm Cache
    If the above doesn’t work, corrupted cache entries might be involved:
    sudo npm cache clean --force
    sudo npm cache verify
    

    Retry the install after this.

  3. Check for Running Processes
    Ensure no other npm/Node processes are using the directory:
    ps aux | grep npm
    

    Kill any lingering ones if needed (e.g., sudo kill <PID>), then retry.

  4. Alternative: Use npx for Testing
    If you just want to test the tool without a full global install, try:
    npx @anthropic-ai/claude-code --help
    

    This downloads and runs it temporarily without modifying your global modules.

Additional Tips

This should get you up and running quickly. If you hit another snag, paste the new log!

Claude Code on npm
Anthropic Docs: Set up Claude Code


Back

x-ai/grok-4-fast

Donate