Search code examples
node.jsamazon-web-servicesnpmaws-cloudshell

How to npm install in AWS CloudShell?


I'm trying to install an npm package in the new AWS CloudShell (comes with pre-configured Node.js support) - but I'm getting a EACCESS error.


npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/lib/node_modules'
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!     /home/cloudshell-user/.npm/_logs/2021-01-06T02_18_33_584Z-debug.log

What's the best way to install npm packages in AWS CloudShell?


Solution

  • To get around this problem, I followed the instructions at https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally:

    First:

    mkdir ~/.npm-global
    npm config set prefix '~/.npm-global'
    

    In your preferred text editor, open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH
    

    Then:

    source ~/.profile