Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Missing write access to /usr/local/lib/node_modules #22

Closed
kyleridolfo opened this issue Nov 17, 2020 · 1 comment
Closed

Missing write access to /usr/local/lib/node_modules #22

kyleridolfo opened this issue Nov 17, 2020 · 1 comment

Comments

@kyleridolfo
Copy link

When doing a fresh install on macOS 11.0.1 (Big Sur), a permissions error is encountered writing to /usr/local/lib/node_modules (which is owned by root).

I found this note but am unsure of how to find or modify the Dockerfile:
https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#global-npm-dependencies

Global npm dependencies
If you need to install global npm dependencies, it is recommended to place those dependencies in the non-root user directory. To achieve this, add the following line to your Dockerfile

ENV NPM_CONFIG_PREFIX=/home/node/.npm-global

ENV PATH=$PATH:/home/node/.npm-global/bin # optionally if you want to run npm global bin without specifying path

% npm install -g git+https://git@github.com/imarc/ops

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!   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/kyle/.npm/_logs/2020-11-17T02_42_43_711Z-debug.log
@jeffturcotte
Copy link
Member

jeffturcotte commented Nov 17, 2020

There are two solutions:

  1. Change the ownership of the /usr/local/lib/node_modules directory.
sudo chown -R $USER /usr/local/lib/node_modules

OR

  1. Change the location for global node scripts:
# make a directory
mkdir $HOME/.npm-global

# then in your .bashrc, .zshrc, or other
NPM_CONFIG_PREFIX=$HOME/.npm-global

# and also make sure the bin dir is in your path
PATH=$PATH:$HOME/.npm-global/bin

Then attempt the install.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants