[npm/mac] npm global로 vue 설치 시 Permission Error

     

    문제상황

    • @vue-cli 을 전역적으로 설치하려 하였으나 다음과 같은 에러 발생
    npm install -g @vue/cli
    • sudo 권한을 주면 설치는 가능하나, 이후 생성되는 파일은 sudo 권한으로도 수정 불가 -> 결론 : 다시 깔자 ^^
    [Error] 
    
    ...
    
    npm ERR! code EACCES
    npm ERR! syscall symlink
    npm ERR! path ../lib/node_modules/@vue/cli/bin/vue.js
    npm ERR! dest /usr/local/bin/vue
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'
    npm ERR!  [Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'] {
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'symlink',
    npm ERR!   path: '../lib/node_modules/@vue/cli/bin/vue.js',
    npm ERR!   dest: '/usr/local/bin/vue'
    npm ERR! }
    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!     /Users/seongeun/.npm/_logs/2023-01-02T11_52_38_376Z-debug-0.log

     

    해결방법

    • 에러로그를 보면 permission denied이 확인됨
    • /usr/local/bin ~ 이후 디렉토리에 접근이 되지 않아 발생한 에러로 보임
    • npm 라이브러리가 설치되는 디렉토리의 owner를 현재 사용자로 변경할 것
    # 다음 명령어를 실행 후 로컬 PC password를 입력한다
    sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
    
    # 다시 설치
    npm install -g @vue/cli

     

    💡 리눅스 명령어 설명

    chown  소유자 변경하겠다.
    -R (chown) 옵션  하위 디렉토리의 파일까지 반복적으로 변경하겠다.
    $(whoami)  사용자 계정 정보를 찾아 치환하겠다.
    $(npm config get prefix)  npm config의 prefix를 가져와서 치환하겠다
    / 소유자를 변경할 디렉토리 경로 
    변경할 디렉토리 경로는 여기다.

     

    Reference


    https://github.com/lumiamitie/TIL/blob/master/js/environment/npm_global_install_permission.md

     

    GitHub - lumiamitie/TIL: Today I Learned

    Today I Learned. Contribute to lumiamitie/TIL development by creating an account on GitHub.

    github.com

     

    728x90

    댓글