“Please try running this command again as Root/Administrator” error when trying to install LESS

后端 未结 11 1975
栀梦
栀梦 2020-12-02 14:09

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 d

相关标签:
11条回答
  • 2020-12-02 14:41

    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.
    0 讨论(0)
  • 2020-12-02 14:44

    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.
    0 讨论(0)
  • 2020-12-02 14:46

    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:

    • npm throws error without sudo
    • https://aralbalkan.com/scribbles/npm-install-g-please-try-running-this-command-again-as-root-administrator/
    • http://foohack.com/2010/08/intro-to-npm/#what_no_sudo
    0 讨论(0)
  • 2020-12-02 14:46

    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.

    0 讨论(0)
  • 2020-12-02 14:48

    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.

    0 讨论(0)
  • 2020-12-02 14:50

    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!!

    0 讨论(0)
提交回复
热议问题