NPM install for packages not working

36,754

Solution 1

This solved the problem for me:

sudo chown -R `whoami` ~/.node/lib/node_modules/bower/
npm install -g bower
bower -v
1.3.12

You shouldn't have to run npm install as sudo.

Solution 2

This worked for me:

I basically gave my user permissions to the directory mentioned right after this -> stack Error: EACCES, unlink..., in your case it would be something like sudo chown -R USERNAME /Users/myname/.

For people who are new to this, don't forget to change USERNAME in the command above with your own, if you don't know your username, simply run whoami to get it.

After that you can install any package without the need to use sudo, npm install -g SomePackage.

Solution 3

Run the global (-g) installs as admin.

> sudo npm install -g bower

You got this error -

npm ERR! Please try running this command again as root/Administrator.

***** UPDATE BELOW *****

Check if it is installed and get the version

> bower -v

You might not be able to see bower now because it installed as admin. Try getting the version number by running

> sudo bower -v

You should see the version number now.

Take ownership of the package with chown

> cd /Users/<username>/.npm
> chown <username> bower*

I personally take ownership of everything in the /Users/ directory. It is your directory and not global.

> chown <username> *

***** UPDATE 2 BELOW *****

It looks like it's a PATH problem now. Do you see the npm directory in the PATH when you type

> echo $PATH

I use MacPorts so npm and node install in the /opt/local/bin and /opt/local/sbin directories. I did a quick check on the net and it looks like you need to have the following /usr/local/bin if you installed the package from the node site.

Check out this article about installing node (particularly the part about the PATH.

That link also references this article on how to modify your PATH.

Hope that helps.

Solution 4

I was having similar issues when trying to install bower through NPM.

I am not an expert on this but was sure it was connected to $PATH and found 2 articles which in combination fixed this for me perfectly.

The first is this gist by Dan Haerbert: https://gist.github.com/DanHerbert/9520689

Dan says

"If you're a Mac Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together. If you install node with Homebrew and then try to do npm update npm -g, you will see an error like this:"

The error he shows is very similar to your original error.

His solution is to re-install node but to make sure that NPM is not installed via homebrew since, as he says:

npm is its own package manager and it is therefore better to have npm manage itself and its packages instead of letting Homebrew do it. Also, using the Homebrew version of npm requires sudo to install global packages. That's also a very bad idea.

He says to uninstall node and then re-install it with the following commands:

brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.org/install.sh | sh

And then to finish up with

export PATH="$HOME/.node/bin:$PATH"

This worked for me and fixed all my issues. I was able to run 'npm install -g bower' without getting the error message.

Finally, before I did the steps above, I wanted to make sure that I had fully uninstalled node & npm. To do that, I followed the following steps from stackoverflow question 11177954, specifically from the answer by Dominic Tancredi, who says:

To recap, the best way (I've found) to completely uninstall node + npm is to do the following:

  1. go to /usr/local/lib and delete any node and node_modules
  2. go to /usr/local/include and delete any node and node_modules directory
  3. if you installed with brew install node, then run brew uninstall node in your terminal
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  5. go to /usr/local/bin and delete any node executable You may need to do the additional instructions as well:
sudo rm /usr/local/bin/npm
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
sudo rm -rf ~/.node-gyp
sudo rm /opt/local/bin/node
sudo rm /opt/local/include/node
sudo rm -rf /opt/local/lib/node_modules

I hope that is of help to someone :-)

Solution 5

I had a similar issue with my mac. I did the followings to solve the problem.

  1. open 'Disk Utility' application
  2. select your hard drive.
  3. run verify disk permissions
  4. run repair disk permissions
Share:
36,754
user2793755
Author by

user2793755

Updated on July 09, 2022

Comments