I'm trying to install LESS on my machine and have installed node already. However, when I enter "node install -g less" I get the following error and am not sure what to do?
FPaulMAC:bin paul$ npm install -g less
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/less'
npm ERR! { [Error: EACCES, unlink '/usr/local/lib/node_modules/less']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/less' }
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" "less"
npm ERR! cwd /usr/local/bin
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! path /usr/local/lib/node_modules/less
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/less'
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/less'
npm ERR! error rolling back { [Error: EACCES, unlink '/usr/local/lib/node_modules/less']
npm ERR! error rolling back errno: 3,
npm ERR! error rolling back code: 'EACCES',
npm ERR! error rolling back path: '/usr/local/lib/node_modules/less' }
npm ERR! not ok code 0
npm has an official page about fixing npm permissions when you get the EACCES (Error: Access) error. The page even has a video.
I also got the problem. This is what I did:
Now, go to nodeJS site, and install again. Select 2nd option in installation option (ie npm package). Install it. You problem must be solved by now.
This will definitely help. Answer by npm itself. https://docs.npmjs.com/getting-started/fixing-npm-permissions
Below is extracted from the URL for your convenience.
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.
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
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.
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
I know this is an old questions but none of the solutions seemed like a good practice hence I am putting how I have solved this issue:
Tried solving this issue by using Homebrew but it was also installing node in
/usr/local directory
which would again causeEACCES
error.Had to use a version manager like nvm for more informations see the official npm guide.
nvm installs node and it's modules in the user's HOME FOLDER thereby solving
EACCES
issues.