LoginSignup
3
4

More than 3 years have passed since last update.

npmコマンドで、permission deniedが発生する

Posted at

状況

babelをインストールしようとすると、permission deniedが発生し、インストールに失敗しました。

$ npm i @babel/core @babel/node @babel/preset-env --save-dev
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /home/user/repos/play_express/node_modules/@babel/core
npm ERR! dest /home/user/repos/play_express/node_modules/@babel/.core.DELETE
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/home/user/repos/play_express/node_modules/@babel/core' -> '/home/user/repos/play_express/node_modules/@babel/.core.DELETE'
npm ERR!  { [Error: EACCES: permission denied, rename '/home/user/repos/play_express/node_modules/@babel/core' -> '/home/user/repos/play_express/node_modules/@babel/.core.DELETE']
npm ERR!   cause:
npm ERR!    { Error: EACCES: permission denied, rename '/home/user/repos/play_express/node_modules/@babel/core' -> '/home/user/repos/play_express/node_modules/@babel/.core.DELETE'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'rename',
npm ERR!      path: '/home/user/repos/play_express/node_modules/@babel/core',
npm ERR!      dest:
npm ERR!       '/home/user/repos/play_express/node_modules/@babel/.core.DELETE' },
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, rename \'/home/user/repos/play_express/node_modules/@babel/core\' -> \'/home/user/repos/play_express/node_modules/@babel/.core.DELETE\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/home/user/repos/play_express/node_modules/@babel/core',
npm ERR!   dest:
npm ERR!    '/home/user/repos/play_express/node_modules/@babel/.core.DELETE',
npm ERR!   parent: 'play_express' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2019-11-12T02_06_04_443Z-debug.log

対応

npmをグルーバルで再インストールしました。

$ rm -rf ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ npm i -g npm

ちなみに、npm config get prefixで、現在のprefixを確認できます。

結果

babelをインストールできました。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4