Error: EACCES, permission denied even after using sudo? - node.js

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! autosave#1.0.3 install: `node ./scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the autosave#1.0.3 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.

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).

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:
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
Install node using nvm (No need to uninstall existing node/npm)
nvm install 12.13.1

Related

How can I install nodejs manually in Linux from terminal

I have downloaded Nodejs in my Linux VM from nodejs.org, I want to install it from terminal. VM have already installed node v0.12.18 manually by someone else, I don't know how to do that. As I am installing nodejs offline, I should not depend on that whether or not npm installed.
I have tried [location]~ npm install node-v15.6.0-linux-x64.tar.gz
Getting below error
[host#machinename ~]$ sudo npm install node-v15.6.0-linux-x64.tar.gz
npm WARN excluding symbolic link bin/npm -> ../lib/node_modules/npm/bin/npm-cli. js
npm WARN excluding symbolic link bin/npx -> ../lib/node_modules/npm/bin/npx-cli. js
npm ERR! addLocal Could not install /home/usermachinename/node-v15.6.0-linux-x64.tar.g z
npm ERR! Linux 3.10.0-1062.9.1.el7.x86_64
npm ERR! argv "/usr/local/lib/nodejs/node-v0.12.18-linux-x64/bin/node" "/usr/loc al/lib/nodejs/node-v0.12.18-linux-x64/bin/npm" "install" "node-v15.6.0-linux-x64 .tar.gz"
npm ERR! node v0.12.18
npm ERR! npm v2.15.11
npm ERR! path /tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! enoent ENOENT, open '/tmp/npm-1637-a9cb4311/unpack-5a7f411732fb/package .json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /home/usermachinename/npm-debug.log
How can I fix this?
You can't install the file using npm install, but since you already have the compressed file for node, my answer will hopefully help you achieve your goal.
First of all you will have to extract the tar.gz file you have node-v15.6.0-linux-x64.tar.gz, to do so just navigate to the folder where the file placed in then do the below command.
tar xf node-v15.6.0-linux-x64.tar.gz
Since you're using Linux the below command will add the new extracted node to your path.
nano ~/.profile
Add the following lines to the end:
# NodeJS
export NODEJS_HOME=/{path_to_the_extracted_folder}/node-v15.6.0-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH
Please make sure you change {path_to_the_extracted_folder} to the path where you extracted the compressed file in the previous step.
Finally you can click CTRL+C to exit nano, type y then click enter.
To refresh the profile file enter the below code
. ~/.profile
Finally
To make sure everything is working fine check the nodeJs version by entering this command node -v it has to print v15.6.0.
You will not have to worry about the previously installed node version since above steps will change the nodeJs path.

Installing SKPM (Sketch Plugin Manager) via npm

I've been attempting to install a npm package, which has been throwing a bunch of errors which I'm not too familiar with. Keep in mind that these errors are after executing sudo npm install -g skpm:
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/skpm/node_modules/keytar/build'
gyp ERR! System Darwin 17.3.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/skpm/node_modules/keytar
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keytar#4.1.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keytar#4.1.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USERNAME/.npm/_logs/2017-12-19T01_53_44_910Z-debug.log
Originally I'd thought that I needed to install keytar to make this work, but after installing I still had the same errors.
Avoid use sudo npm -g install
During gyp compilation you will have such problems again and again.
Fixing permissions is the solution.
Quote from npm docs:
You can fix this problem using one of three options:
Change the permission to npm's default directory.
Change npm's default directory to another directory.
Install Node with a package manager that takes care of this for you. You should back-up your computer before moving forward.
Option 1: Change the permission to npm's default directory
Find the path to npm's directory: npm config get prefix For many systems, this will be /usr/local.
WARNING: If the displayed path is just /usr, switch to Option 2 or you
will mess up your permissions.
Change the owner of npm's directories to the name of the current user
(your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Option 2: Change npm's default directory to another directory
There are times when you do not want to change ownership of the
default directory that npm uses (i.e. /usr) as this could cause some
problems, for example if you are sharing the system with other users.
Instead, you can configure npm to use a different directory
altogether. In our case, this will be a hidden directory in our home
folder.
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 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
Option 3: Use a package manager that takes care of this for you.
If you're doing a fresh install of Node on Mac OS, you can avoid this
problem altogether by using the Homebrew package manager. Homebrew
sets things up out of the box with the correct permissions.
brew install node
usually EACCES: permission denied occurs trying to install a package globally (with -g) without providing permissions. Supposing that you are on os with sudo, try call
sudo npm install -g skpm
or, if you don't want it global
npm install skpm
I found the issue as to why skpm was not installing.
Make sure you install x-code + command line tools access
This fixed the issue and SKPM installed.

NPM won't install any package on Mac. New, clean build. `EACCES` & other errors

I've just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.
I installed Git via their git-2.0.1-intel-universal-snow-leopard.pkg (http://git-scm.com/downloads) in their default /usr/local/git/bin/git location.
I installed Node via their node-v0.10.30.pkg (http://nodejs.org/download/) in their default /usr/local/bin/node location.
The final step of Node's installer package included a note that they also installed NPM in their default /usr/local/bin/npm location.
My $PATH echoes /usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin (it contains /usr/local/bin).
Running npm install -g bower results in:
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Home
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Home/npm-debug.log
npm ERR! not ok code 0
Running similar installations (npm install -g yo, npm install -g grunt, npm install -g nvm, npm install -g npm) results in what appears to be the same list of errors.
Several people online suggest forcing the installation via sudo, but several others warn this could cause later issues. The manuals for these packages seem not to mention requirement of sudo, and in some cases, they have advised contacting NPM when this issue arises.
Running npm cache clear does not correct the issue.
Running ls -la in the home (~) directory shows my Mac OS X username as the owner of my .npm directory: drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm
Does anyone know what has gone wrong and how to correct this? Thank you.
By the way, I solved this issue by changing the owner of /usr/local to be myself, in order to allow NPM to modules in its default location without further requiring sudo for each package's installation.
sudo chown -R `whoami` /usr/local
EACCES is an error of not having access on doing an operation.
Taken the line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' we can see that npm was unable to create a directory in the given location.
The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:
npm ERR! Please try running this command again as root/Administrator.
To run as administrator, you have to prefix those commands with sudo. That is:
sudo npm install -g bower. You will be required to type in a password for security reasons.
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
to install nodejs and npm as yourself NOT root do these commands (linux) :
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
cd v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax : npm install xxxxx -g
always use the -g for global
nodejs install gives you npm as well :
ls -la ${HOME}/bin/nodejs/bin
I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:
First, you can manage multiple versions of Node.js on the same machine (which you will want to do sooner or later).
Second, you get around all the access problems you experience when installing Node.js without it. At least that's my experience.
Basically it's as easy as running
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
from the command line.
(SOLUTION ANSWER)
Hi Guys,
I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)
You could simply add "sudo" before your commands what will force it.
For example:
sudo npm install gulp -g
or
sudo npm install browser-sync -g
Enjoy!
It's generally not advised to run sudo unless absolutely necessary.
For issues like this, NPM can solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.
I had a similar issue setting up a new machine, and installing NPM took care of the issue.

nodejs npm package | npm link issue

I am trying to make a npm package (plugin) to install the little JS framework through node, have come up with the required package.json as well.
After running the npm link command on Mac terminal, got to see the following errors.
npm ERR! Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR! { [Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Repos/GIT/JavaScript-Boilerplate' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "link"
npm ERR! cwd /Repos/GIT/JavaScript-Boilerplate
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm ERR! path /Repos/GIT/JavaScript-Boilerplate
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '/Repos/GIT/JavaScript-Boilerplate'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Repos/GIT/JavaScript-Boilerplate/npm-debug.log
npm ERR! not ok code 0
P.S. I am pretty new to nodejs but have strong experience in JavaScript, let me know if you need more detail around.
EDIT - Got to resolved the issues given above but now getting more issues as below:
6495 verbose false,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/node_modules unbuild contextify#0.1.5
6496 info postuninstall contextify#0.1.5
6497 verbose about to build /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery
6498 info /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery unbuild
6499 verbose from cache /Repos/GIT/JavaScript-Boilerplate/node_modules/jquery/package.json
6500 info preuninstall jquery#1.8.3
6501 info uninstall jquery#1.8.3
6502 verbose true,/Repos/GIT/JavaScript-Boilerplate/node_modules,/Repos/GIT/JavaScript-Boilerplate/node_modules unbuild jquery#1.8.3
6503 info postuninstall jquery#1.8.3
6504 error contextify#0.1.5 install: `node-gyp rebuild`
6504 error `sh "-c" "node-gyp rebuild"` failed with 1
6505 error Failed at the contextify#0.1.5 install script.
6505 error This is most likely a problem with the contextify package,
6505 error not with npm itself.
6505 error Tell the author that this fails on your system:
6505 error node-gyp rebuild
6505 error You can get their info via:
6505 error npm owner ls contextify
6505 error There is likely additional logging output above.
6506 error System Darwin 12.3.0
6507 error command "node" "/usr/local/bin/npm" "link"
6508 error cwd /Repos/GIT/JavaScript-Boilerplate
6509 error node -v v0.10.4
6510 error npm -v 1.2.18
6511 error code ELIFECYCLE
6512 verbose exit [ 1, true ]
enter code here
enter code here
Looks like I am close to it :)
Permissions you used when installing Node will be required when doing things like writing in your npm directory (npm link, npm install -g, etc.).
You probably ran node installation with root permissions, that's why the global package installation is asking you to be root.
Solution 1: NVM
Don't hack with permissions, install node the right way.
On a development machine, you should not install and run node with root permissions, otherwise things like npm link, npm install -g will need the same permissions.
NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.
Uninstall Node (root permission will probably be required).
To remove all previously installed npm global modules, see those answers.
Then install NVM following instructions on this page.
Install Node via NVM: nvm install stable
Now npm link, npm install -g will no longer require you to be root.
Solution 2: Install packages globally for a given user
Don't hack with permissions, install npm packages globally the right way.
If you are on OSX or Linux, you can create a user dedicated directory for your global package and setup npm and node to know how to find globally installed packages.
Check out this great article for step by step instructions on installing npm modules globally without sudo.
See also: npm's documentation on Fixing npm permissions.
The easiest way to solve this would be to run the same command again using sudo:
sudo npm link
Please don't change the owner of the /usr/local directory, as this might a) have further implications on installed application and b) might compromise the security on your system. Using sudo is the right way to solve this.
This can be fixed in linux or in my case WSL by setting the global package directory to be in user space rather than root.
First create a dir for global packages
mkdir ~/.npm-packages
Then tell npm where to store globally installed packages
npm config set prefix ~/.npm-packages
Finally ensure npm will find installed binaries and man pages by adding the following to your .bashrc/.zshrc:
NPM_PACKAGES=~/.npm-packages
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

Getting errors when trying to install socket.io globally

I am new to node, npm, socket.io. Found many guides that are fairly useful, but I am encountering some errors which I don't understand the cause, hopefully you can help me out.
npm install socket.io -g
returns ...
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm ERR! error installing socket.io#0.9.4
npm ERR! error rolling back socket.io#0.9.4 Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "socket.io" "-g"
npm ERR! cwd /Users/Kinglee
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.0-beta-4
npm ERR! path /usr/local/lib/node_modules/socket.io/.npmignore
npm ERR! code EACCES
npm ERR! message EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Kinglee/npm-debug.log
however when i did npm install socket.io, there was no error, everything was fine.
Sorry forget to add this info here ...
I actually tried sudo npm install socket.io and it installed without error but when i try to cd ~/node_modules, I don't see socket.io, this cause 'socket.io not found' error when i try to do require('socket.io') as I follow this tutorial here (http://blog.koostudios.com/?p=470)
Kind of confused fellow here :/
The most important portion is:
EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
This means you do not have permission to delete this file.
I assume this means you ran the command as your standard user account, which will not have write permission into /usr/.
Prepend sudo to your command to re-run the command with administrator privileges:
sudo npm install socket.io -g
Your local configuration may not have /usr/local/lib/node_modules/ in node's default module loading locations. The module loading path is controlled via the NODE_PATH environment variable (before starting node) or the require.paths variable (once node is running). Because I prefer to keep local configuration separated from the program, I'd prefer to set the environment variable to modify paths, though the other mechanism may be useful for long-lived applications that must remain up even when the environment changes. (This is definitely an advanced use.)
To change the NODE_PATH variable for a single instance, sh and its derivatives will let you simply add NODE_PATH=/path before the command. For example, change:
node ./foo.js
to
NODE_PATH=/usr/local/lib/node_modules ./foo.js
If you have multiple directories, use the standard :-separated directories, just as you would for PATH:
NODE_PATH=/usr/local/lib/node_modules:/home/sarnold/node_modules ./foo.js
To make this persistent, use the shell's export builtin to export the value of the NODE_PATH variable to all children and place the modification in your shell's start up files, such as ~/.bashrc:
export NODE_PATH=/usr/local/lib/node_modules
This will take effect in all new shells automatically. You can source this file into currently-running shells if you don't wish to restart them:
source ~/.bashrc
Just leaving this here, as it helped me with a similar problem:
NPM no longer working
Had some good answers.
Hope it helps.

Resources