Kokizzu
Kokizzu

Reputation: 26898

NPM error when installing globally even when directories are writable

i have this error when try to install coffee-script using this command:

npm install -g --verbose coffee-script opal

these are the error message:

npm ERR! Error: EACCES, symlink '../lib/node_modules/coffee-script/bin/coffee'
npm ERR!  { [Error: EACCES, symlink '../lib/node_modules/coffee-script/bin/coffee']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '../lib/node_modules/coffee-script/bin/coffee' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm info postuninstall [email protected]
npm ERR! Error: EACCES, symlink '../lib/node_modules/opal/bin/opal-node'
npm ERR!  { [Error: EACCES, symlink '../lib/node_modules/opal/bin/opal-node']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '../lib/node_modules/opal/bin/opal-node' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

the folder /usr/local/bin and /usr/local/lib/node_modules are owned and writable by current user, and i do not want to run that npm command using root, how to know which folder that the npm tried to make a symlink to?

i'm using npm 1.2.9-1chl1~quantal1 and nodejs 0.8.19-1chl1~quantal1

Upvotes: 14

Views: 22146

Answers (5)

Kokizzu
Kokizzu

Reputation: 26898

ah, using this command:

npm -g bin

it would output something like this:

/usr/bin # this is the folder nodejs wanted to write..

then you may chmod or chown it so it can be written for installation.

Upvotes: 4

Mohsen
Mohsen

Reputation: 65835

You can chown NPM's bin to your user name with this one liner to solve this problem:

$ chown -R `whoami` `npm -g bin`

Upvotes: 15

jbasko
jbasko

Reputation: 7330

Had a similar problem. Turns out I had something in project/node_modules directory installed with sudo. In my case it was some of the dependencies AND ALSO .bin directory. I deleted these bad directories, then ran npm install again and it succeeded. I did also reinstall global protractor and phantomjs, but not sure if that was required. I am sure it was the bad (i.e. root-owned) .bin directory causing this.

Upvotes: 0

HeberLZ
HeberLZ

Reputation: 14103

I had a similar problem at NPM modules won't install globally without sudo, the issue was that when i installed node i did it with sudo via chris/lea ppa repo.

My solution was to uninstall node and then install it this way:

Download latest stable node sources from nodejs.org #in my case node-v0.10.20.tar.gz

tar -zxf node-v0.10.20.tar.gz #uncompress sources

cd node-v0.10.20 #enter uncompressed folder

sudo chown $USER -R /usr/local

./configure --prefix=/usr/local && make && make install

PD: If you don't want to change ownership of the /usr/local folder, you can install it somewhere you already own. The problem of this approach is that you will have to bind the installation folder with the bash command line so that we can use the node command later on

mkdir ~/opt

./configure --prefix=~/opt && make && make install

echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc #or ~/.profile or ~/.bash_profile or ~/.zshenv depending on the current Operative System

With either of those approaches, you will be able to do the following without using sudo

npm install -g --verbose coffee-script opal

Upvotes: 2

Pascal Belloncle
Pascal Belloncle

Reputation: 11389

your node installation uses system directories. Use sudo when using -g

sudo npm install -g --verbose coffee-script opal

Upvotes: 20

Related Questions