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

后端 未结 11 1976
栀梦
栀梦 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:51

    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

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

    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

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

    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

    0 讨论(0)
  • 2020-12-02 15:01

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

    0 讨论(0)
  • 2020-12-02 15:05

    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.

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