Error: EACCES: permission denied, access '/usr/lib/node_modules'

后端 未结 7 1933
甜味超标
甜味超标 2020-12-07 07:51

I am trying install typescript with command npm install -g typescript, and returns this error :

    npm ERR! Error: EACCES: permission denied, a         


        
相关标签:
7条回答
  • 2020-12-07 08:08

    I have same issue with webpack server installation on globally, Use steps Solved my issue, my be work for you.

    Steps mention above There: Back-up your computer before you start.

    Make a directory for global installations:

    1. mkdir ~/.npm-global

    Configure npm to use the new directory path:

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

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

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

    Back on the command line, update your system variables:

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

    0 讨论(0)
  • 2020-12-07 08:09

    It's not recommended to use sudo with npm install, follow the steps from npmjs official docs instead :)

    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.

    npm install -g typescript
    

    Source: https://docs.npmjs.com/getting-started/fixing-npm-permissions

    0 讨论(0)
  • 2020-12-07 08:13

    Please follow npm site - https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

    "If you see an EACCES error when you try to install a package globally, you can either: Reinstall npm with a node version manager (recommended), or Manually change npm’s default directory"

    I followed recommended way - installed nvm. its resolved my issue

    0 讨论(0)
  • 2020-12-07 08:14

    this worked for me.

    sudo npm install -g coffee-script
    

    then

    sudo npm install -g typescript
    
    0 讨论(0)
  • 2020-12-07 08:21

    1) Go to the directory “/usr/local/lib/node_modules

    2) Click on the folder and right click Get info

    3) Click the lock at the bottom right

    4) Key in your window password to unlock

    5) Check both the value of Wheel and Everyone to Read & Write

    6) Go back to your terminal and try to install the Typescript again

    0 讨论(0)
  • 2020-12-07 08:26

    Not very sure if this could be the right solution to this problem, but I hope this could help others with similar situation that already tried the following:

    • Applied the recommendation on the npm website
    • Checked for the right permissions for the node_modules folder and found nothing wrong
    • Used sudo npm install <package> (solution which I do not recommend anyway) with or without -g and had no expected result

    The solution to this problem pointed out when I noticed that while I was trying to install the axios package with npm, the directory containing the entire project was opened in Visual Studio Code. So I closed it and retried installation again. Surprise, the installation worked like a charm.

    For trying to replicate same problem I was using Ubuntu 18.04 LTS on WSL (maybe this has something to do with Windows permissions)

    This could be the solution for this question also: Error: EACCES: permission denied, access '/usr/local/lib/node_modules' react

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