Error: EACCES, permission denied even after using sudo?

16,397

Solution 1

You have two options: Either fix your npm setup, so you can use npm -g, or install autosave locally.

To install locally (i.e. in node_modules within your current directory), run npm install autosave (without -g). Then you can run ./node_modules/.bin/autosave or ./node_modules/autosave/bin/autosave to start autosave.

To fix your npm setup, so you can use -g without root permissions (recommended):

In your home dir (assuming /Users/Brent/), create a file called .npmrc with the following content:

cache = /Users/Brent/.npm/cache
globalconfig = /Users/Brent/.npm/npmrc
globalignorefile = /Users/Brent/.npm/npmignore
prefix = /Users/Brent/.npm

And add ~/.npm/lib/node_modules to your NODE_PATH, e.g. by putting the following in .bashrc (assuming that your shell is bash) to allow the modules to be found, and append ~/.npm/bintoPATHso you can run any installed binary (i.e. runautosave` from anywhere):

export NODE_PATH=$HOME/.npm/lib/node_modules
export PATH=$PATH:$HOME/.npm/bin

(changes to .bashrc only take effect when you load the shell, or use . ~/.bashrc; if you want to use the new setup without reloading the shell, just run that line (export ...) in your current shell).

Solution 2

As of 2020, here is the recommended solution by npm. It worked for me (OSX). (No need to change any path configuration or .bashrc)

Steps:

  1. Install nvm by running below command.

If you are using bash

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash

If you are using zsh

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | zsh
  1. Install node using nvm (No need to uninstall existing node/npm)

nvm install 12.13.1

Share:
16,397
Digital Brent
Author by

Digital Brent

I am a web developer. Partial to warm climates. I designed my website theme completely from scratch. I love the challenge that web design and other types of development offer to me. I primarily code, but I also dabble in design and I live for making and creating things. The best feeling is when you see an idea come from your head and you can materialize it in the real world.

Updated on June 15, 2022

Comments

  • Digital Brent
    Digital Brent almost 2 years

    I am trying to set up a chrome extension that will automatically save the changes I make to my website with the inspect element feature. The idea is that you'll be able to make real time changes to the website without having to go back into the ide to save the changes and re-upload and everything. The extension is called DevTools Autosave. I've been following the instructions from this site. I'm trying to install this on a mac.

    I've installed node.js and the extension already. When I got to the part in the instructions where it talks about which commands to run in the terminal I've tried both with and without the "sudo" in front of the "npm install -g autosave" command but I always get this error:

    Error: EACCES, permission denied
        at Function.startup.resolveArgv0 (node.js:815:23)
        at startup (node.js:58:13)
        at node.js:906:3
    
    npm ERR! [email protected] install: `node ./scripts/install.js`
    npm ERR! Exit status 8
    npm ERR! 
    npm ERR! Failed at the [email protected] install script.
    npm ERR! This is most likely a problem with the autosave package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     node ./scripts/install.js
    npm ERR! You can get their info via:
    npm ERR!     npm owner ls autosave
    npm ERR! There is likely additional logging output above.
    npm ERR! System Darwin 14.0.0
    npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "autosave"
    npm ERR! cwd /Users/Brent
    npm ERR! node -v v0.10.33
    npm ERR! npm -v 1.4.28
    npm ERR! code ELIFECYCLE
    npm ERR! not ok code 0
    

    Anyone know how I can fix this? I can't find anyone that is having this problem and I've been on a few different forums now but can't find a solution. Thanks in advance.