Help us understand the problem. What is going on with this article?

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

状況

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

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした