aws-sam-cli: sudo npm install fails

Most likely a bug with go-npm (https://github.com/sanathkr/go-npm) because it handles the installation. But filing a Issue here nevertheless for other folks to be aware of. A fix is on the way.

sudo npm install -g aws-sam-local
Password:
-
> aws-sam-local@0.1.1 postinstall /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local
> go-npm install

Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.1.1/sam_0.1.1_darwin_amd64.tar.gz
fs.js:681
  return binding.rename(pathModule._makeLong(oldPath),
                 ^

Error: EACCES: permission denied, rename 'bin/sam' -> '/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/sam'
    at Error (native)
    at Object.fs.renameSync (fs.js:681:18)
    at /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:62:12
    at /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:51:9
    at ChildProcess.exithandler (child_process.js:204:7)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Socket.<anonymous> (internal/child_process.js:319:11)
    at emitOne (events.js:77:13)
npm ERR! Darwin 16.6.0
npm ERR! argv "/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/node" "/Users/sanathkr/.nvm/versions/node/v4.3.0/bin/npm" "install" "-g" "aws-sam-local"
npm ERR! node v4.3.0
npm ERR! npm  v2.14.12
npm ERR! code ELIFECYCLE

npm ERR! aws-sam-local@0.1.1 postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the aws-sam-local@0.1.1 postinstall script 'go-npm install'.
npm ERR! This is most likely a problem with the aws-sam-local package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     go-npm install
npm ERR! You can get their info via:
npm ERR!     npm owner ls aws-sam-local
npm ERR! There is likely additional logging output above.

> aws-sam-local@0.1.1 preuninstall /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local
> go-npm uninstall


npm ERR! Please include the following file with any support request:
npm ERR!     /Users/sanathkr/workspace/GoWorkspace/src/github.com/awslabs/aws-sam-local/npm-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 37 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Following fixed for me

npm config set unsafe-perm=true

(Option 1 from that document should fix most ppl’s permissions issues)

sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

did the trick from me. Thanks mhart

npm install -g go-npm then npm install -g aws-sam-local worked for me

npm config set unsafe-perm=true

worked for me on mac os

worked for me on Ubuntu 16.04 LTS with

npm config set unsafe-perm=true

This pull request on go-npm should allow for a local rather than global installation of aws-sam-local - sanathkr/go-npm#3

Installing aws-sam-local locally avoids the issues with permissions and let’s you control the version of the module from package.json.

Worked for me on Ubuntu 16.04 with

npm config set unsafe-perm=true
npm install -g go-npm 
npm install -g aws-sam-local

For those who look only on last comment (like me): don’t use chown -R ... in case when npm config get prefix points to /usr. Read carefully this article instead: https://docs.npmjs.com/getting-started/fixing-npm-permissions

Can someone please edit or remove this and this!? That’s really dangerous if you’re a fool like me and /usr is your node prefix!

Might be worth adding this to the documentation?

https://docs.npmjs.com/getting-started/fixing-npm-permissions

For some reason mine was some weird user:

drwxr-xr-x   8 24561     wheel           272 Aug 21 09:38 node_modules

A chown to my user fixed it 👍

chown -R georgmao node_modules/

A solution would be to have go-npm download binaries to /tmp directory instead of aws-sam-local/bin. What does /tmp mean in Windows is still up for debate. Needs a bit more thinking.

Use os.tmpdir() ?

npm install -g go-npm then npm install -g aws-sam-local worked for me

Installed Node.js through apt-get on Ubuntu 17.04. Also needed sudo ln -s /usr/bin/nodejs /usr/bin/node for go-npm to work. See: https://github.com/nodejs/node-v0.x-archive/issues/3911

Setting unsafe-perm=true did not fix this for me.

Windows 10, gitbash shell, node 8.9.1, npm 5.5.1

$ npm install -g aws-sam-local

> aws-sam-local@0.2.4 postinstall d:\npm\npm\node_modules\aws-sam-local
> go-npm install

Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.4/sam_0.2.
4_windows_amd64.tar.gz
fs.js:766
  return binding.rename(pathModule._makeLong(oldPath),
                 ^

Error: ENOENT: no such file or directory, rename 'd:\npm\npm\node_modules\aws-sam-local\bin\sam.
exe' -> 'd:\npm\npm\bin\sam.exe'
    at Object.fs.renameSync (fs.js:766:18)