Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
967 views
in Technique[技术] by (71.8m points)

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

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

    npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
    npm ERR!     at Error (native)
    npm ERR!  { Error: EACCES: permission denied, access '/usr/lib/node_modules'
    npm ERR!     at Error (native)
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'access',
    npm ERR!   path: '/usr/lib/node_modules' }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    npm ERR! Linux 4.4.0-93-generic
    npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "typescript"
    npm ERR! node v6.11.2
    npm ERR! npm  v3.10.10
    npm ERR! path npm-debug.log.1024969454
    npm ERR! code EACCES
    npm ERR! errno -13
    npm ERR! syscall open
    
    npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
    npm ERR!     at Error (native)
    npm ERR!  { Error: EACCES: permission denied, open 'npm-debug.log.1024969454'
    npm ERR!     at Error (native)
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'open',
    npm ERR!   path: 'npm-debug.log.1024969454' }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /npm-debug.log
    jramirez@jramirez:/$ ^C
    jramirez@jramirez:/$ npm install typescript
    npm WARN checkPermissions Missing write access to /
    /
    └── [email protected] 
    
    npm WARN enoent ENOENT: no such file or directory, open '/package.json'
    npm WARN !invalid#1 No description
    npm WARN !invalid#1 No repository field.
    npm WARN !invalid#1 No README data
    npm WARN !invalid#1 No license field.
    npm ERR! Linux 4.4.0-93-generic
    npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
    npm ERR! node v6.11.2
    npm ERR! npm  v3.10.10
    npm ERR! path /
    npm ERR! code EACCES
    npm ERR! errno -13
    npm ERR! syscall access
    
    npm ERR! Error: EACCES: permission denied, access '/'
    npm ERR!     at Error (native)
    npm ERR!  { Error: EACCES: permission denied, access '/'
    npm ERR!     at Error (native) errno: -13, code: 'EACCES', syscall: 'access', path: '/' }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    npm ERR! Linux 4.4.0-93-generic
    npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "typescript"
    npm ERR! node v6.11.2
    npm ERR! npm  v3.10.10
    npm ERR! path npm-debug.log.2387664261
    npm ERR! code EACCES
    npm ERR! errno -13
    npm ERR! syscall open
    
    npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
    npm ERR!     at Error (native)
    npm ERR!  { Error: EACCES: permission denied, open 'npm-debug.log.2387664261'
    npm ERR!     at Error (native)
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'open',
    npm ERR!   path: 'npm-debug.log.2387664261' }
    npm ERR! 
    npm ERR! Please try running this command again as root/Administrator.
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /npm-debug.log

Additionally, I run npm install typescript (without -g), but it doesn't work. Does there exist any other way to install typescript? My OS is Linux Ubuntu 16.04. I seldom use node and don't know like to fix this issue.

My question is: exactly which directories need that permission?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...