Error: EACCES: permission denied, access '/usr/lib/node_modules' - shell

I am trying install typescript with command npm install -g typescript, and it returns this error:
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path npm-debug.log.1024969454
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: 'npm-debug.log.1024969454' }
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! /npm-debug.log
jramirez#jramirez:/$ ^C
jramirez#jramirez:/$ npm install typescript
npm WARN checkPermissions Missing write access to /
/
└── typescript#2.5.2
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#1 No description
npm WARN !invalid#1 No repository field.
npm WARN !invalid#1 No README data
npm WARN !invalid#1 No license field.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path /
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, access '/'
npm ERR! at Error (native) errno: -13, code: 'EACCES', syscall: 'access', path: '/' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Linux 4.4.0-93-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
npm ERR! node v6.11.2
npm ERR! npm v3.10.10
npm ERR! path npm-debug.log.2387664261
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: 'npm-debug.log.2387664261' }
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! /npm-debug.log
Additionally, I run npm install typescript (without -g), but it doesn't work. Does there exist any other way to install typescript?
My OS is Linux Ubuntu 16.04.
I seldom use node and don't know like to fix this issue.
My question is: exactly which directories need that permission?

It's not recommended to use sudo with npm install, follow the steps from npmjs official docs instead :)
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g typescript
Source: https://docs.npmjs.com/getting-started/fixing-npm-permissions

When installing global packages in ubuntu, you need special write permissions as you are writing to the usr/bin folder. It is for security reasons.
So, everytime you install a global package, use:
sudo npm install -g [package-name]
for your specific case:
sudo npm install -g typescript
When you try it without -g all that you are doing is installing the package locally in whatever folder you are in:
so: npm install typescript will create a node_modules folder in the folder you are in.

I have same issue with webpack server installation on globally, Use steps Solved my issue, my be work for you.
Steps mention above There: Back-up your computer before you start.
Make a directory for global installations:
1. mkdir ~/.npm-global
Configure npm to use the new directory path:
2. npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
3. export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables:
4. source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global

Not very sure if this could be the right solution to this problem, but I hope this could help others with similar situation that already tried the following:
Applied the recommendation on the npm website
Checked for the right permissions for the node_modules folder and found nothing wrong
Used sudo npm install <package> (solution which I do not recommend anyway) with or without -g and had no expected result
The solution to this problem pointed out when I noticed that while I was trying to install the axios package with npm, the directory containing the entire project was opened in Visual Studio Code. So I closed it and retried installation again.
Surprise, the installation worked like a charm.
For trying to replicate same problem I was using Ubuntu 18.04 LTS on WSL (maybe this has something to do with Windows permissions)
This could be the solution for this question also:
Error: EACCES: permission denied, access '/usr/local/lib/node_modules' react

1) Go to the directory “/usr/local/lib/node_modules”
2) Click on the folder and right click Get info
3) Click the lock at the bottom right
4) Key in your window password to unlock
5) Check both the value of Wheel and Everyone to Read & Write
6) Go back to your terminal and try to install the Typescript again

It is recommended to use nvm to manage your node versions and npm suggests this to be the recommended solution of access errors: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

Please follow npm site - https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
"If you see an EACCES error when you try to install a package globally, you can either:
Reinstall npm with a node version manager (recommended),
or
Manually change npm’s default directory"
I followed recommended way - installed nvm. its resolved my issue

this worked for me.
sudo npm install -g coffee-script
then
sudo npm install -g typescript

Related

How to install Nodemon via Terminal on Mac

I'm trying to install Nodemon via terminal by typing:
npm install -g nodemon
But my terminal throws the following error:
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/nodemon'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/ayrix/.npm/_logs/2022-12-15T18_50_01_089Z-debug-0.log
Does anyone has an idea how I can change the permisson to install the utility?
Thanks
It didn't take long to figure it out though.
I just had to type the sudo command infront like
sudo npm install -g nodemon
I think it's still worth to keep that post in case that someone else faces the same issue.

mac os don't install gulp [duplicate]

This question already has answers here:
NPM modules won't install globally without sudo
(16 answers)
Closed 2 years ago.
I can’t install gulp, I looked at a lot of solves, but couldn't find a solution.
Air-Yaroslav:~ yaroslav$ npm install --global gulp-cli
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR! stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/yaroslav/.npm/_logs/2020-03-17T09_50_56_975Z-debug.log
It started to install, but then gives an error.
Any ideas?
As the error says, your user profile doesn't have access to write to the global node_modules folder at /usr/local/lib/node_modules.
Run the same command with sudo, which will use root permissions to execute the same command:
sudo npm install --global gulp-cli

Catalina wont let me install gulp or other apps using npm

I have a fresh install of Mac OS Catalina and it wont let me install npm apps. I tried both sudo and non sudo.
npm install --global browser-sync
but got this error,
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/browser-sync
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules/browser-sync
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/browser-sync'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/browser-sync'] {
npm ERR! stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules/browser-sync'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/browser-sync'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/nicholasdixon/.npm/_logs/2019-12-14T07_09_23_421Z-debug.log
It's a UNIX issue from reinstalling the OS.
You can fix it by typing into your terminal:
sudo chown -R $USER /usr/local/lib/node_modules
This worked for me, hope it will do the same for you.

Angular installation failure in Ubuntu 16.04 (Xenial Xerus)

Angular CLI always shows an error while running the installation command and also the ng shows no such command found. How do I get rid of this problem?
shivashish-Inspiron-3521% cd Angular-project
shivashish-Inspiron-3521% ls
shivashish-Inspiron-3521% sudo npm install -g angular/cli
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/angular/cli.git
npm ERR!
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /home/shivashish/.npm/_logs/2018-11-25T10_01_17_050Z-debug.log
shivashish-Inspiron-3521% ls
shivashish-Inspiron-3521% ng new app
zsh: command not found: ng
shivashish-Inspiron-3521% node -v
v8.13.0
I run again and now I get this:
shivashish-Inspiron-3521% npm install -g #angular/cli
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/shivashish/.npm/_logs/2018-11-25T13_53_57_814Z-debug.log
This is because it should be #angular/cli instead of angular/cli. The correct command is:
sudo npm install -g #angular/cli
according to Step 1: Install the Angular CLI
PS: please don't forget to use sudo when installing globally (-g parameter) on linux

npm permission issue on fresh install of Homestead / Vagrant / Laravel

Two days dealing with this issue and it is winning.
I have a fresh install of Windows 10 host, running the latest versions of Vagrant, laravel/homestead (Ubuntu 18.04 LTS box, v 6.0.0), Virtualbox, laravel, git for windows, node.js for windows.
vagrant, git, virtualbox are set to run as administrator in windows.
I create a Laravel project called blog like this:
vagrant#homestead:~/src$ composer create-project --prefer-dist laravel/laravel blog
All creates OK. I then try and install npm like this:
vagrant#homestead:~/src/blog$ npm install -g npm#latest
And I get:
npm WARN checkPermissions Missing write access to /usr/lib/node_modules/npm
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules/npm'
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules/npm'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules/npm\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules/npm' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2018-05-05T00_57_41_110Z-debug.log
But when i check vagrant user permissions:
vagrant#homestead:~/src/blog$ groups
vagrant adm cdrom sudo dip www-data plugdev lxd lpadmin sambashare
So I solve this with the not recommended by npm message:
vagrant#homestead:~/src/blog$ sudo npm install -g npm#latest
I now go and install an npm package like highcharts:
vagrant#homestead:~/src/blog$ npm install --save highcharts
npm WARN rollback Rolling back highcharts#6.1.0 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515'
npm ERR! path /home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/home/vagrant/src/blog/node_modules/highcharts/package.json.2262439515' -> '/home/vagrant/src/blog/node_modules/highcharts/package.json'
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2018-05-05T01_10_24_241Z-debug.log
I try sudo to install package, same result
vagrant#homestead:~/src/blog$ sudo npm install --save --no-bin-links highcharts
npm WARN rollback Rolling back highcharts#6.1.0 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036'
npm ERR! path /home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/home/vagrant/src/blog/node_modules/highcharts/package.json.1984492036' -> '/home/vagrant/src/blog/node_modules/highcharts/package.json'
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2018-05-05T01_58_13_140Z-debug.log
The result is a highchatrts folder in node_modules with only the packaje.json.1984492036 file in it.
I cannot seem to find a way around this. Using --no-bin-links gives the same error.
Any help is appreciated.
I got it all working by running npm install from the git host os, not from the ubuntu vm. Not what I wanted but I move forward and have learned something and creeped closer to insanity...
I had this same issue two days ago, try running sudo npm install --unsafe-perm , undo any changes you made first though, cause i don't know how valet works (sad Linux user)

Resources