Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

状況

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をインストールできました。

quzq
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away