아래와 같은 에러가 발생하는 경우가 있다.
WARN Failed to install dependencies. Please run 'npm install' in "/Users/greendot/blog" folder.
➜ blog npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /Users/greendot/.npm/_cacache/index-v5/b2/37
npm ERR! errno EACCES
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 501:20 "/Users/greendot/.npm"
npm ERR! A complete log of this run can be found in: /Users/greendot/.npm/_logs/2024-04-20T06_10_50_264Z-debug-0.lo
해결
mac에서 권한 설정이 안되어 있어서 그렇다.
- path 찾기 npm config get prefix
- permission 변경
npm관련 디렉토리의 권한을 변경한다.
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node\_modules,bin,share}
위와 같이 하면 sudo 없이 npm 설치가 정상적으로 된다.