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

I try to install typescript using the command npm install -g typescriptand return 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 /
    /
    └── typescript@2.5.2 

    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 also npm install typescript(without -g), but doesn’t work, or is there no other way to install typescript? My OS is Linux Ubuntu 16.04. I rarely use nodeand do not know how to fix this problem.

My question is: exactly, which directories need these permmisions?

+33
source share
5 answers

It is not recommended to use sudo with npm installation, follow the instructions from the official npmjs docs :)

Create a directory for global installations:

mkdir ~/.npm-global

Configure npm to use the new directory path:

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

~/.profile :

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

:

source ~/.profile

: sudo.

npm install -g typescript

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

+100

ubuntu usr/bin. .

, , , :

sudo npm install -g [package-name]

:

sudo npm install -g typescript

-g , , , :

: npm install typescript node_modules , .

+17

Webpack , , .

, . .

:

1. mkdir ~/.npm-global

npm :

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

~/.profile :

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

:

4. source ~/.profile

: sudo.

npm install -g jshint

2-4 ENV (, ~/.profile):

NPM_CONFIG_PREFIX=~/.npm-global

+5

1) "/usr/local/lib/node_modules"

2) Click on the folder and right-click Get Information

3) Click on the lock in the lower right

4) Enter the window password to unlock

5) Check the value of the wheel and each to read and write

6) Go back to your terminal and try installing Typescript again.

0
source

it worked for me.

sudo npm install -g coffee-script

then

sudo npm install -g typescript
-3
source

Source: https://habr.com/ru/post/1685097/


All Articles