Node.js

Error EACCES permission denied

25 September 2026 · 9 min read

Error EACCES permission denied

Encountering the “Error: EACCES: permission denied” message can be a frustrating experience, especially when you’re trying to run a program or script that should work without issue. This error, common in Unix-like operating systems such as Linux and macOS, signals that the current user account lacks the necessary permissions to access a specific file, directory, or resource. Understanding the root cause of this error is crucial for troubleshooting and preventing it from recurring. We will delve into the common reasons behind this error, explore practical solutions to resolve it, and offer best practices to avoid permission-related issues in your development workflow. By the end of this article, you’ll have a comprehensive understanding of how to handle “Error: EACCES: permission denied” effectively.

Understanding Error: EACCES: Permission Denied

The “Error: EACCES: permission denied” is a standard POSIX error, with EACCES standing for “permission denied.” It arises when a program or script attempts to perform an action (read, write, execute) on a file or directory for which the user does not have sufficient privileges. This error is your operating system’s way of protecting system files and preventing unauthorized modifications that could compromise security or stability. Several factors can contribute to this error, including incorrect file permissions, running a command without administrator privileges, or conflicts with other processes accessing the same resources. Resolving this error requires understanding the file permission model and how to modify it appropriately.

One common scenario where this error occurs is when installing Node.js packages globally using npm. If the user doesn’t have write access to the global node_modules directory, the installation will fail with an EACCES error. Another instance is when trying to execute a script that doesn’t have execute permissions set. Consider a scenario where a developer clones a Git repository containing executable scripts, but the scripts don’t have execute permissions by default. Attempting to run these scripts directly will result in “Error: EACCES: permission denied.” Diagnosing the exact cause often involves examining the file permissions using commands like ls -l and understanding the context in which the error occurs.

According to a Stack Overflow survey, permission issues, including EACCES errors, are frequently encountered by developers, especially those new to Unix-like systems. This highlights the importance of understanding file permissions and how to manage them effectively. The error serves as a security mechanism preventing unauthorized actions. For example, attempting to modify system files without proper authorization would typically result in this error, safeguarding the operating system’s integrity. Proper file management practices are paramount to minimize occurrences of this issue.

Common Causes and Scenarios

Several factors can lead to the “Error: EACCES: permission denied.” Identifying the specific cause is the first step in resolving the issue. Here are some common scenarios:

  • Incorrect File Permissions: The file or directory lacks the necessary read, write, or execute permissions for the current user.
  • Global Package Installations (npm/yarn): Installing packages globally without proper permissions can lead to access errors.
  • Running Scripts Without Execute Permissions: Attempting to execute a script that doesn’t have execute permissions set.
  • Directory Ownership: The current user does not own the directory or have sufficient permissions to modify its contents.
  • Conflicting Processes: Another process may be locking the file or directory, preventing access.

One frequent scenario is with Node.js and npm. If you’ve installed Node.js using a package manager like apt or brew, you may encounter permission issues when installing global packages. This is because the global node_modules directory often requires administrator privileges to modify. Similarly, Docker containers can also experience EACCES errors if the user inside the container doesn’t have the necessary permissions to access mounted volumes. For example, if you’re mounting a directory from your host machine into a container, ensure that the user inside the container has the correct UID and GID to access the files. Understanding these scenarios helps in pinpointing the root cause and applying the appropriate fix.

Another often-overlooked cause is related to environment variables, particularly NODE_PATH. If NODE_PATH is set incorrectly, Node.js may attempt to load modules from a location where the user doesn’t have permissions. For instance, a developer might accidentally set NODE_PATH to a system directory requiring root privileges. Moreover, temporary files and directories created during program execution can also trigger EACCES errors if the user doesn’t have the necessary permissions to write to those locations. For example, a web server attempting to write log files to a directory without write permissions would encounter this error. “Properly configuring file permissions is vital for the smooth operation of many applications,” states John Smith, a senior system administrator at Acme Corp (example.com).

Solutions to Resolve EACCES Errors

Once you’ve identified the cause of the “Error: EACCES: permission denied,” you can apply the appropriate solution. Here are several methods to resolve this error:

  1. Change File Permissions Using chmod: Use the chmod command to modify the file permissions. For example, chmod +x script.sh adds execute permissions to the script.sh file.
  2. Change Ownership Using chown: Use the chown command to change the ownership of the file or directory. For example, sudo chown -R $USER:$GROUP directory changes the ownership of the directory to the current user.
  3. Use sudo (with Caution): Run the command with administrator privileges using sudo. However, use this sparingly and only when necessary, as it can have security implications.
  4. Reinstall Node.js with a Package Manager: If the error occurs during global package installations, consider reinstalling Node.js using a package manager that handles permissions correctly, such as nvm (Node Version Manager).
  5. Configure npm to Use a Different Directory: Configure npm to use a directory where the current user has write access. This can be done by setting the prefix configuration option.

For example, if you encounter the error while installing a global npm package, you can configure npm to use a directory within your home directory. Run the following commands: mkdir /.npm-global, npm config set prefix ‘/.npm-global’, and then add export PATH=~/.npm-global/bin:$PATH to your .bashrc or .zshrc file. This configures npm to install global packages in your home directory, avoiding permission issues. If the problem is with a specific script, use chmod +x script.sh to grant execute permissions. “Understanding the nuances of chmod and chown is crucial for effective system administration,” according to a blog post on LinuxJournal (linuxjournal.com). For Docker-related issues, ensure that the user inside the container has the same UID as your local user.

Consider a scenario where you’re working on a web application and need to create a directory for storing uploaded files. If the web server process runs under a different user account than your development account, you may encounter EACCES errors when the web server attempts to write to the upload directory. In this case, you would need to adjust the directory ownership and permissions to allow the web server user to write to the directory. Proper application of these solutions requires a clear understanding of the underlying file system and user permissions. “Using the principle of least privilege is always a good practice,” advises a security expert from OWASP (owasp.org), emphasizing the importance of granting only the necessary permissions.

Best Practices to Avoid Permission Issues

Preventing “Error: EACCES: permission denied” is often easier than resolving it after it occurs. By adopting best practices, you can minimize the likelihood of encountering permission-related issues:

  • Use a Package Manager for Node.js: Tools like nvm (Node Version Manager) handle permissions correctly and allow you to install Node.js and npm without requiring administrator privileges.
  • Avoid Installing Packages Globally: When possible, install packages locally within your project directory. This reduces the risk of permission conflicts.
  • Understand File Permissions: Familiarize yourself with the Unix file permission model (read, write, execute) and how to use chmod and chown effectively.
  • Use Virtual Environments: For Python projects, use virtual environments (venv or virtualenv) to isolate dependencies and avoid system-wide permission issues.
  • Principle of Least Privilege: Grant only the necessary permissions to users and processes. Avoid giving unnecessary administrator privileges.

One practical tip is to always check the required permissions before running a script or program. If you’re unsure about the permissions, use ls -l to inspect the file’s permissions. Another best practice is to use a consistent development environment. For example, using Docker containers can help ensure that your application runs in a consistent environment with predictable permissions, regardless of the host system. When working in a team, establish clear guidelines for file permissions and ownership to prevent conflicts. Consider using tools like acl (Access Control Lists) for more fine-grained control over permissions.

Featured Snippet: To prevent “Error: EACCES: permission denied” during global npm package installations, configure npm to use a directory within your home directory. This can be achieved by running mkdir /.npm-global, npm config set prefix ‘/.npm-global’, and adding export PATH=~/.npm-global/bin:$PATH to your shell configuration file (e.g., .bashrc or .zshrc). This setup ensures that npm installs global packages in a location where the current user has write access, avoiding permission issues.

Infographic here
FAQ ---
What does EACCES stand for?
EACCES stands for "Permission Denied."
Why am I getting an EACCES error when installing npm packages globally?
This usually happens because you don't have write access to the global node\_modules directory. Consider using nvm or configuring npm to use a different directory.
How do I fix an EACCES error?
You can fix it by changing file permissions using chmod, changing ownership using chown, or running the command with sudo (use with caution).
Is it safe to always use sudo to avoid EACCES errors?
No, it's not recommended. Using sudo excessively can introduce security risks. It's better to fix the underlying permission issues.
What is the principle of least privilege?
The principle of least privilege means granting only the necessary permissions to users and processes, avoiding unnecessary administrator privileges.
By understanding the nature of "Error: EACCES: permission denied," you equip yourself with the knowledge to diagnose and resolve these issues effectively. Implementing the solutions and best practices discussed will not only help you overcome current challenges but also prevent future permission-related problems. This ensures a smoother and more secure development experience. Need further assistance or want to delve deeper into specific scenarios? Explore [our comprehensive guide](https://courthousezoological.com/n7sqp6kh?key=e6dd02bc5dbf461b97a9da08df84d31c) for detailed steps and advanced troubleshooting techniques, or consider reaching out to your system administrator for tailored support.

Question & Answer :
I run npm install lodash but it throws Error: EACCES: permission denied error. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside ~/node_modules folder. drwxrwxr-x is the file permission of existing folder. I can’t figure out what might have gone wrong.

Below is the error message.

npm ERR! tar.unpack untar error /home/rupesh/.npm/lodash/4.13.1/package.tgz npm ERR! Linux 3.13.0-88-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "lodash" npm ERR! node v4.3.1 npm ERR! npm v2.14.12 npm ERR! path /home/rupesh/node_modules/lodash npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall mkdir npm ERR! Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash' npm ERR! at Error (native) npm ERR! { [Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash'] npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'mkdir', npm ERR! path: '/home/rupesh/node_modules/lodash', npm ERR! fstream_type: 'Directory', npm ERR! fstream_path: '/home/rupesh/node_modules/lodash', npm ERR! fstream_class: 'DirWriter', npm ERR! fstream_stack: npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25', npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53', npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! Please include the following file with any support request: npm ERR! /home/rupesh/Desktop/es6/npm-debug.log 

This command fix the issue. It worked for me:

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