This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
Description
C:\Program Files (x86)\nodejs\node_modules
npm ERR! code EACCES
I have been having this issue for a couple of months and can find no solution.
ANY time that I try to run npm install -g
I get this error. I have tried a multitude of different possible solutions, but none work. Some of the things that I have tried are:
- Running
cmd
as administrator - Using
gitshell
- Using
runas /user:<localmachinename>\<AdministratorAccountName> "npm install -g"
(as well as with my user name) - I’ve update npm to 3.2.0 using npm-windows-upgrade
- Running CCleaner on the registry, didn’t help
None of these solve the issue. I have been all over stackoverflow, Googled every term that I could think of and looked through the open and closed issues on here to no avail. I can install packages locally — without the -g
tag — but there are certain node packages that I would like to have available globally.
I have created a gist of the npm debug log here. WARNING: it is 20,000+ lines long
Windows Version: Windows 10 Home (upgraded from windows 7)
npm version: 3.2.0
node version: 0.12.1
Any help on this issue would be appreciated, even if this issue is deemed to not be one with npm itself.
Thank you in advance.
Error: EACCES: permission denied with npm happens while trying to install a new npm package globally in a system.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related npm queries.
How to fix «Error: EACCES: permission denied with npm» ?
When this issue happens, you will see an error message like the one given below:
npm ERR! Error: EACCES, open '/Users/letscodepare/.npm/-/all/.cache.json'
npm ERR! { [Error: EACCES, open '/Users/letscodepare/.npm/-/all/.cache.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/letscodepare/.npm/-/all/.cache.json' }
npm ERR! Please try running this command again as root/Administrator.
.....
.....
We can either reinstall npm with a node version manager or manually change npm’s default directory.
1. Reinstalling npm with a node version manager
To publish and install packages to and from the public npm registry we must install Node.js and the npm command-line interface.
We can do this either with a Node version manager or a Node installer.
Note: npm Enterprise requires npm 4.4.x or greater. To download the latest version of npm, on the command line, run the following command:
$ npm install -g npm
The steps to follow are given below:
i. Checking version of npm and Node.js
We can use the following commands for this:
node -v
npm -v
ii. Using a Node version manager to install Node.js and npm
Node version managers allow us to install and switch between multiple versions of Node.js and npm.
OSX or Linux Node version managers
- nvm
- n
Windows Node version managers
- nodist
- nvm-windows
iii. Using a Node installer to install Node.js and npm
If we are unable to use a Node version manager, we can use a Node installer to install both Node.js and npm on our system.
- Node.js installer
- NodeSource installer
OS X or Windows Node installers
We can use one of the installers from the Node.js download page. Also, we must ensure to install the version labeled LTS. Other versions have not yet been tested with npm.
Linux or other operating systems Node installers
If you’re using Linux or another operating system, use one of the following installers:
NodeSource installer.
One of the installers on the Node.js download page.
2. Manually change npm’s default directory (Linux)
To minimize the chance of permissions errors, we can configure npm to use a different directory.
In this example, we will create and use the hidden directory in the home directory.
Following are the steps to do:
i. Firstly, take a backup of the computer.
ii. Then from the command line, in the home directory, we need to create a directory for global installations.
We can use the following:
$ mkdir ~/.npm-global
3. For configuring npm to use the new directory path, we can use the following path:
$ npm config set prefix '~/.npm-global'
4. Then, In a text editor, open or create a ~/.profile file and add the following line:
export PATH=~/.npm-global/bin:$PATH
5. After that we have to update the system variables using the following:
source ~/.profile
6. Now, to test the new configuration, install a package globally without using sudo:
$ npm install -g jshint
[Need assistance in fixing Linux System errors? We can help you. ]

When you try to install an npm package globally using the npm install -g <package name>
command, you may find the following error:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
The warning above means that your current terminal user doesn’t have “write access” to the /usr/local/lib/node_modules
folder.
Because you can’t write any new file and folder to the node_modules
folder, npm won’t be able to complete the installation.
You should see other errors below the warning as a consequence of the warning:
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/rimraf
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, ...
npm ERR!
npm ERR! The operation was rejected by your operating system.
Without the write access, npm will not be able to create folders and write the files for the package you are trying to install.
There are three ways to fix this error:
This tutorial will help you resolve the missing write access error.
Installing npm modules globally with the sudo command
You can run the npm install
command as root user by adding sudo
before the command:
sudo npm install -g @angular/cli
The sudo
command allows you to execute terminal command as the “root” user. You will be asked for your password when you invoke this command.
By calling the sudo
command, the error message with code EACCES should be resolved because root user has access to everything on your computer.
The drawback of this method is that you also need to add sudo
when you want to uninstall the package later.
As an alternative, you can change the owner of the node_modules
folder instead
Fix missing write access using chown command
The first way is to change the owner of the node_modules
folder, which must be owned by user “root” by default.
The following command will change the owner of the folder to your current user. I will explain the command below:
sudo chown -R $USER /usr/local/lib/node_modules
The chown
command is used to change the owner of the folder.
The -R
option means that the change owner command will be executed recursively, changing not only the node_modules
folder owner, but also the rest of the files and folders inside it.
Then, the $USER
is an environment variable that will be replaced with the current username you used to login to your computer.
Finally, the folder path /usr/local/lib/node_modules
is included to tell the terminal to change the owner of that folder.
By running the command above, you will be able to install npm packages again because the node_modules
folder now belongs to your current user.
But rather than running the command and changing the owner of the folder, I’d recommend you install NVM instead.
Fixing missing write access using NVM
NVM or Node Version Manager is a software that’s designed to be installed per-user basis.
It allows you to install multiple versions of NodeJS on your computer so that you can upgrade or downgrade your NodeJS version as needed.
The reason why using NVM would fix the missing write access command is that by default, NVM will install NodeJS versions to a folder under your current user.
For example, my NodeJS version is currently installed under the /Users/nsebhastian/
folder:
nvm which current
/Users/nsebhastian/.nvm/versions/node/v10.19.0/bin/node
When you install global packages using NVM, the package will be installed under the version’s lib/
folder:
/Users/nsebhastian/.nvm/versions/node/v10.19.0/lib/node_modules
By using NVM, you will have the ability to install different versions of NodeJS on your computer and you will automatically fix the missing write access error. I’m currently using it for my computer, and I’d recommend you to use it too 😉
You can learn how to install NVM here
Now you’ve learned how to resolve the permission denied error message caused by missing write access. Nice work! 👍
The “Error: EACCES: permission denied, scandir” error can also occur when using NPM (Node Package Manager) and trying to install a package. This is because NPM needs to access certain directories on your system, such as log files under the home directory or the global node_modules directory, and the error occurs when it doesn’t have the proper permissions to do so.
The Problem:
While running the npm command, I faced the following error message.
NPM error message:
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] { errno: -13, code: 'EACCES', syscall: 'scandir', path: '/root/.npm/_logs' }
Generally, users receive this error, while running the npm commands with the root account. Here, we will discuss two solutions to resolve this error message.
Solution 1:
It is recommended not to run the npm command as the root account. This can be harmful to your system. So you can simply switch to a non-root account and run the same command.
Most probably this will resolve your issue.
Solution 2:
If you are bound to run the npm command as the root account. Then make sure the current working directory, in which you are running the npm command is owned by the root account.
So, change the current working directory (CWD) owner to root.
chown root:root .
Then run your npm commands, and it should run without any error.
Conclusion
In summary, the “Error: EACCES: permission denied, scandir” error can occur when using NPM if the user does not have the proper permissions to access a specific directory. In this article, we have discussed two solutions to resolve this error on your system.
When working with Node.js and npm, encountering the error “EACCES: permission denied” is a common issue. This error indicates that npm does not have the necessary permissions to access or modify certain files or directories on your system. Understanding and resolving this error is crucial for a smooth development experience.
Table of Contents
Causes of EACCES Error
Understanding File Permissions
The root cause of the EACCES error often lies in file permissions. Unix-based systems (like Linux and macOS) use a permission system to control access to files and directories. Permissions determine who can read, write, or execute a file.
Common Scenarios
- Global Package Installation: Installing npm packages globally can trigger this error if npm lacks the required permissions.
- Directory Ownership: If directories used by npm are owned by the root user, non-root users may encounter permission issues.
- Cache Issues: Corrupted npm cache can also lead to permission errors.
How to Diagnose the Error
Recognizing the Error
The error message typically looks like this:
Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
This indicates that npm tried to access a directory but was denied permission.
Identifying Affected Files/Directories
Check the specific files or directories mentioned in the error message. This helps pinpoint where permission changes are needed.
Quick Fixes
Using sudo
Running npm commands with sudo can temporarily resolve permission issues:
sudo npm install -g
However, using sudo frequently is not recommended as it can lead to other issues.
Changing Ownership
Change the ownership of npm directories to the current user:
sudo chown -R $USER /usr/local/lib/node_modules
sudo chown -R $USER ~/.npm
Modifying File Permissions
Adjust file permissions using the chmod command:
chmod -R 755 /path/to/directory
Custom Directory for Global Packages
Configure npm to use a different directory for global packages:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Update your PATH variable:
export PATH=~/.npm-global/bin:$PATH
Add this line to your shell configuration file (~/.bashrc or ~/.zshrc).
Long-Term Solutions
Local Package Installation
Install packages locally rather than globally to avoid permission issues:
npm install
Using Node Version Manager (NVM)
NVM allows you to manage multiple Node.js versions and avoids permission problems:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
nvm install node
Creating an NPM Wrapper Script
Create a script to run npm commands with necessary permissions without using sudo
.
Docker for Isolated Environments
Using Docker containers can isolate your development environment, mitigating permission issues.
Preventing Future Issues
Best Practices
- Avoid global installations when possible.
- Regularly update Node.js and npm to the latest versions.
- Maintain a dedicated development environment with appropriate permissions.
Regular Backups
Keep backups of your projects to safeguard against data loss due to permission issues.
Final Thoughts
The “Error: EACCES: permission denied” can disrupt your workflow, but understanding its causes and solutions helps mitigate its impact. By applying the quick fixes and long-term strategies outlined above, you can prevent this error from recurring and maintain a smooth development experience.
Frequently Asked Questions (FAQs)
The EACCES error occurs when npm lacks the necessary permissions to access or modify certain files or directories on your system.
Common solutions include using sudo
, changing directory ownership, modifying file permissions, and configuring npm to use a different directory for global packages.
This error happens because npm tries to install packages in directories that require elevated permissions. Solutions include changing ownership of npm directories or using NVM to manage Node.js versions.
Written By,
Md Monayem Islam
Hey, I’m Md Monayem Islam. I’m a Full Stack Developer with extensive expertise in Laravel (PHP), Vue.js (TypeScript), and API development. Over the years, I’ve honed my skills in building dynamic and scalable web applications.
Previously, I worked on a variety of projects, creating robust solutions and enhancing the user experience for clients worldwide.
Now, I’m here to share my knowledge and help you develop web applications.
Want a FREE Consultation?
I am here to assist with your queries. Schedule now!