Resolving “EACCES: permission denied” Error During npm Install on macOS

Resolving "EACCES: permission denied" Error During npm Install on macOS

10 November 2024 Stephan Petzl Leave a comment Tech-Help

Encountering the “EACCES: permission denied, mkdir” error while attempting to install packages globally using npm on macOS is a common issue. This guide will walk you through effective solutions to resolve this error and ensure smooth installations.

Understanding the Error

The error typically occurs when npm attempts to create directories in system locations that require elevated permissions. This is especially prevalent when using the -g option to install packages globally.

Solution 1: Using npm with Elevated Permissions

One straightforward approach is to use npm with elevated permissions directly. Execute the following command in your terminal:

sudo npm install -g appium --unsafe-perm=true --allow-root

This allows npm to bypass permission restrictions during the installation process.

Solution 2: Reconfiguring npm Permissions

For a more sustainable solution, consider reconfiguring npm to operate globally without the need for elevated permissions:

Option 1: Using a Node Version Manager

  1. Install nvm (Node Version Manager) by running:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

    After installation, verify by running: command -v nvm.

  2. Install the latest LTS release of NodeJS:
    nvm install --lts
  3. Set the newly installed NodeJS as the default:
    nvm alias default lts/*

Option 2: Changing Directory Ownership

If nvm is not an option, adjust the ownership of npm’s directories:

sudo chown -R $(your_user) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(your_user) ~/.npm ~/.npmrc

This grants your user account the necessary permissions to write to these directories.

Enhancing Testing Efficiency with Repeato

While configuring your development environment, consider streamlining your mobile app testing process with Repeato. As a no-code test automation tool for iOS and Android, Repeato offers a faster, more stable alternative to traditional tools like Appium. By leveraging computer vision and AI, Repeato simplifies the creation and execution of automated tests, enhancing your project’s efficiency and reliability.

For more details on setting up test environments, refer to our documentation section.

Like this article? there’s more where that came from!