"Please try running this command again as Root/Administrator" error when trying to install LESS
Asked Answered
B

13

65

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
Bobsled answered 28/10, 2014 at 15:48 Comment(1)
possible duplicate of NPM throws error without sudoFool
J
73

Re Explosion Pills "An installation can run arbitrary scripts and running it with sudo can be extremely dangerous!"

Seems like using sudo is the wrong way of doing it.

"Change the owner of the files in your /usr/local folder to the current user:"

sudo chown -R $USER /usr/local

Then run the install

node install -g less

Check out:

Jainism answered 31/12, 2014 at 17:0 Comment(2)
The term 'sudo' is not recognized as the name of a cmdlet, function, script file, or operable program.Philbrook
Just for reference, in OSX High Sierra, it is no longer possible to chown /usr/local as it is restricted.Haye
E
32

Just prepend sudo to the beginning of your command. As stated before, an installation runs some scripts that might be dangerous but I saw installing globally helps a lot and is way simpler.

Run sudo npm install -g less

Evaporite answered 15/12, 2015 at 8:29 Comment(1)
You probably meant "prepend", not "append", and even then, it's not the best solution.Pathless
E
31

Honestly this is bad advice from npm. An installation can run arbitrary scripts and running it with sudo can be extremely dangerous! You could do sudo npm install -g less to install it globally, but instead I would recommend updating your npm settings:

#~/.npmrc
prefix=~/.npm_modules

Then you can update your path:

#~/.bashrc or ~/.zshrc, etc.
export PATH=$PATH:$HOME/.npm_modules/bin

Then you don't require root permissions to perform the installation and you can still use the binary.

This would only apply to your user, however. If you want the entire system to be able to use the module you would have to tell everyone to add your path. More complicated and robust solutions would include adding a folder with node modules / binaries that a group could install to and adding that to everyone's path.

Endoderm answered 28/10, 2014 at 15:57 Comment(3)
@StackOverflow I am saying that in your .npmrc and .bashrc/.zshrc configuration files you should do these updates. The # is to signify a comment and shows the filenameEndoderm
@StackOverflow ~ means your home directory. ~/.npmrc should be an actual file.Endoderm
This would be the right answer for anyone working on a shared server, too. Messing with /usr/local for the sake of npm only makes sense on a single-user system.Libriform
P
15

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

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

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

  1. Make a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. Open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH

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

Persist answered 31/10, 2017 at 17:52 Comment(1)
Worked for me. Atom SASS Autocompile package error "/bin/sh: node-sass: command not found" required installing node-sass globally.Janelljanella
M
5

I kept having this problem because windows was setting my node_modules folder to Readonly. Make sure you uncheck this.

enter image description here

Melcher answered 14/11, 2017 at 17:46 Comment(0)
E
2

This is what I had to do to get started with a Less compiler to avoid issues as mentionned in the OP:

  1. Install node.js
  2. Install NPM with Terminal: sudo npm install npm -g
  3. Install a Less compiler with Terminal: sudo npm install -g less (the sudo makes all the difference)
  4. If you're using PHPstorm: Go to "Preferences… > Plugins" and install NodeJS-plugin (might need to "browse repositories" to find it) and restart PHPstorm (as prompted)
  5. After that go to Plugins once again: Install Less compiler (might need to "browse repositories" to find it) and restart PHPstorm (as prompted)
  6. Once you have a project set up, go to "Settings > Tools > Filewatchers" and add "Less". The path (of the "Program") should read something like this: /usr/local/bin/lessc
  7. Make sure Track only root files is checked in the settings of 6.
Eggert answered 28/12, 2015 at 17:8 Comment(0)
M
1

npm has an official page about fixing npm permissions when you get the EACCES (Error: Access) error. The page even has a video.

You can fix this problem using one of two options:

  1. Change the permission to npm's default directory.
  2. Change npm's default directory to another directory.
Mcnully answered 10/3, 2016 at 3:0 Comment(0)
D
0

In my case i needed to update the npm version from 5.3.0 → 5.4.2 .

Before i could use this -- npm i -g npm .. i needed to run two commands which perfectly solved my problem. It is highly likely that it will even solve your problem.

Step 1: sudo chown -R $USER /usr/local

Step 2: npm install -g cordova ionic

After this you should update your npm to latest version

Step 3: npm i -g npm

Then you are good to go. Hope This solves your problem. Cheers!!

Doublehung answered 24/9, 2017 at 3:35 Comment(1)
whats the need to install ionic to resolve this permission issue. 'npm install -g cordova ionic'Ludmilla
I
0

I also got the problem. This is what I did:

  1. Uninstalled nodeJs from Control Panel > Uninstall a program
  2. There are 2 folders in users//appData/roaming --> npm folder and npm-cache folder. Delete both of these.

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.

Intricate answered 28/9, 2017 at 10:48 Comment(0)
D
0

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 cause EACCES error.

Had to use a version manager like nvm for more informations see the official npm guide.

For various operating system.

nvm installs node and it's modules in the user's HOME FOLDER thereby solving EACCES issues.

Demoniac answered 29/5, 2018 at 11:54 Comment(0)
S
0

I was getting this issue for instaling expo cli and I fixed by just following four steps mentioned in the npm documentation here.

Problem is some version of npm fail to locate folder for global installations of package. Following these steps we can create or modify the .profile file in Home directory of user and give it a proper PATH there so it works like a charm.

Try this it helped me and I spent around an hour for this issue. My node version was 6.0

Steps I follow

Back up your computer. On the command line, in your home directory, create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

npm config set prefix '~/.npm-global'

In your preferred text editor, open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH

On the command line, update your system variables:

source ~/.profile

To test your new configuration, install a package globally without using sudo:

npm install -g jshint

Sanmiguel answered 16/10, 2020 at 7:47 Comment(0)
C
0

I've been having this issue for a while and finally found this solution (for Mac)...

This article will walk you through how to change your current profile into root user OR... for any purpose if you want to log into root (profile) yourself.

https://support.apple.com/en-us/HT204012#:~:text=Click%20Open%20Directory%20Utility.&text=in%20the%20Directory%20Utility%20window,use%20for%20the%20root%20user.

If this doesn't work try:

https://apple.stackexchange.com/questions/316304/how-to-run-a-root-admin-shell-in-terminal

Hope this helps anyone who reads this ... it's def annoying running into that issue over and over again.

Coypu answered 4/2, 2022 at 3:48 Comment(1)
Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.Recondite
J
0

I got the same issue and was able to reslove by adding export PATH="$PATH":"$HOME/.pub-cache/bin" to my .zshrc file

Jargon answered 29/8, 2023 at 19:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.