Question:
I’ve created a pre-configured node.js instance on AWS using ElasticBeanstalk, but the application does not run correctly. SO I connected to the instance and found out there is no node or angular cli, so I installed them manually. I then tried to run npm install in the application folder but failed, here is the output error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
[ec2-user@ip current]$ npm install npm WARN checkPermissions Missing write access to /var/app/current/node_modules/tslib npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ngx-loading-bar/core npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/animations npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/common npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/compiler npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/core npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/forms npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/http npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/platform-browser npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/platform-browser-dynamic npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular/router npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ng-bootstrap/ng-bootstrap npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ngx-loading-bar/http-client npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ngx-loading-bar/router npm WARN checkPermissions Missing write access to /var/app/current/node_modules/bootstrap npm WARN checkPermissions Missing write access to /var/app/current/node_modules/ngx-mydatepicker npm WARN checkPermissions Missing write access to /var/app/current/node_modules/ngx-toastr npm WARN checkPermissions Missing write access to /var/app/current/node_modules npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ngx-loading-bar npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@angular npm WARN checkPermissions Missing write access to /var/app/current/node_modules/@ng-bootstrap npm WARN ng2-nouislider@1.7.7 requires a peer of nouislider@^9.0.0 || ^10.0.0 but none is installed. You must install peer dependencies yourself. npm ERR! path /var/app/current/node_modules/tslib npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/var/app/current/node_modules/tslib' npm ERR! { Error: EACCES: permission denied, access '/var/app/current/node_modules/tslib' npm ERR! stack: 'Error: EACCES: permission denied, access \'/var/app/current/node_modules/tslib\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/var/app/current/node_modules/tslib' } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! A complete log of this run can be found in: npm ERR! /home/ec2-user/.npm/_logs/2018-02-15T00_53_02_546Z-debug.log |
I already installed node using version manager nvm, and tried also chown permission to nodejs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
drwxr-xr-x 16 nodejs nodejs 4096 Feb 15 00:25 node_modules [ec2-user@ip current]$ cd node_modules/ [ec2-user@ip node_modules]$ ls -la total 64 drwxr-xr-x 16 nodejs nodejs 4096 Feb 15 00:25 . drwxr-xr-x 5 nodejs nodejs 4096 Feb 15 00:26 .. drwxr-xr-x 11 nodejs nodejs 4096 Feb 15 00:25 @angular drwxr-xr-x 5 nodejs nodejs 4096 Feb 15 00:25 bootstrap drwxr-xr-x 13 nodejs nodejs 4096 Feb 15 00:25 core-js drwxr-xr-x 6 nodejs nodejs 4096 Feb 15 00:25 font-awesome drwxr-xr-x 4 nodejs nodejs 4096 Feb 15 00:25 ng2-nouislider drwxr-xr-x 3 nodejs nodejs 4096 Feb 15 00:25 @ng-bootstrap drwxr-xr-x 5 nodejs nodejs 4096 Feb 15 00:25 @ngx-loading-bar drwxr-xr-x 4 nodejs nodejs 4096 Feb 15 00:25 ngx-mydatepicker drwxr-xr-x 8 nodejs nodejs 4096 Feb 15 00:25 ngx-toastr drwxr-xr-x 3 nodejs nodejs 4096 Feb 15 00:25 nouislider drwxr-xr-x 14 nodejs nodejs 4096 Feb 15 00:25 rxjs drwxr-xr-x 4 nodejs nodejs 4096 Feb 15 00:25 symbol-observable drwxr-xr-x 3 nodejs nodejs 4096 Feb 15 00:25 tslib drwxr-xr-x 4 nodejs nodejs 4096 Feb 15 00:25 zone.js |
I appreciate if someone could help me resolve this problem,
Thanks.
Answer:
It’s a LINUX permissions issue, your ec2-user doesn’t have write permissions in that directory.
I faced the same issue recently and my workaround was the following:
Note that I’m not an expert in UNIX neither AWS so maybe there is a better/cleaner/easier solution to this issue.
Having node and npm installed globally:
Log as root user using: sudo su
and run npm install
Having node and npm only installed in ec2-user:
- Log as root user using:
sudo su
- Create a group of users:
sudo groupadd mygroup
- Now that the group exists, add users to it:
1 2 3 |
sudo usermod -a -G mygroup root sudo usermod -a -G mygroup uc2-user |
- Now all that’s left is to set the permissions on the directory:
1 2 3 |
sudo chgrp -R mygroup /path/to/the/directory sudo chmod -R 777 /path/to/the/directory |
- Now you can exit as root user:
exit
and runnpm install
as ec2-user