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:
-
> [email protected] 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! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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.
> [email protected] 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
This is a problem because the post-install npm script runs as non-sudo user, however /Users/sanathkr/.nvm/versions/node/v4.3.0/lib/node_modules/aws-sam-local directory is created as root user. post-install script isn't able to move the file from a root directory to non-root directory.
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.
Does this happen on npm v4.x as well? I only ask because npm@5 has changed the way permissions are being used and that's caused some bugs for install scripts + root, ie: https://github.com/npm/npm/issues/17851
It happens on npm 2 actually, whatever is bundled with Node 4.3.0
Ah, yeah, I should've spotted that from the install log – ok, probably not related then!
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() ?
Hmm, I'm getting the same issue with a sudo install. But without a sudo I get other permissions issues:
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "aws-sam-local"
npm ERR! node v7.10.0
npm ERR! npm v4.2.0
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
@georgmao - on my machine, /usr/local/lib/node_modules is owned by my user.
Maybe the first time you ran npm was as root, so those directories were created with root ownership.
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/
I have the same issue:
[email protected] postinstall /usr/local/lib/node_modules/aws-sam-local
go-npm install
Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.0/sam_0.2.0_linux_amd64.tar.gz
fs.js:681
return binding.rename(pathModule._makeLong(oldPath),
^
Error: EACCES: permission denied, rename 'bin/sam' -> '/usr/local/bin/sam'
at Error (native)
Might be worth adding this to the documentation?
https://docs.npmjs.com/getting-started/fixing-npm-permissions
(Option 1 from that document should fix most ppl's permissions issues)
sudo chown -R $(whoami) /usr/local/{lib/node_modules,bin,share}
yeah looks good to me.
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
did the trick from me. Thanks mhart
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
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.
Not sure this issue should be closed. I have followed the steps from Option 2 from the NPM fixing-npm-permissions post
. Used option 2 because as the instructions list npm config get prefix resolves to /usr.
If anyone wants to reproduce, I am attempting to install sam-local into the following Docker image:
https://hub.docker.com/r/cloudbees/jnlp-slave-with-java-build-tools/tags/ (tag 2.0.1)
Run as the Jenkins user:
fs.js:809
return binding.rename(pathModule._makeLong(oldPath),
^
Error: ENOENT: no such file or directory, rename 'bin/sam' -> '/home/jenkins/.npm-global/bin/sam'
at Error (native)
at Object.fs.renameSync (fs.js:809:18)
at /home/jenkins/.npm-global/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:62:12
at /home/jenkins/.npm-global/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:51:9
at ChildProcess.exithandler (child_process.js:197:7)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
npm ERR! Linux 4.9.49-moby
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "aws-sam-local"
npm ERR! node v6.9.4
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'go-npm install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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 information on how to open an issue for this project with:
npm ERR! npm bugs aws-sam-local
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls aws-sam-local
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/jenkins/npm-debug.log
Run as root:
sh: 1: go-npm: Permission denied
npm ERR! Linux 4.9.49-moby
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "aws-sam-local"
npm ERR! node v6.9.4
npm ERR! npm v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] postinstall: `go-npm install`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'go-npm install'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, 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 information on how to open an issue for this project with:
npm ERR! npm bugs aws-sam-local
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls aws-sam-local
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/jenkins/npm-debug.log
In windows I have the same error:
C:\WINDOWS\system32>npm install -g aws-sam-local
> [email protected] postinstall C:\Users\fabio.jose\AppData\Roaming\npm\node_modules\aws-sam-local
> go-npm install
Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.2/sam_0.2.2_windows_amd64.tar.gz
fs.js:742
return binding.rename(pathModule._makeLong(oldPath),
^
Error: ENOENT: no such file or directory, rename 'C:\Users\fabio.jose\AppData\Roaming\npm\node_modules\aws-sam-local\bin\sam.exe' -> 'C:\Users\fabio.jose\AppData\Roaming\npm\bin\sam.exe'
at Object.fs.renameSync (fs.js:742:18)
at C:\Users\fabio.jose\AppData\Roaming\npm\node_modules\aws-sam-local\node_modules\go-npm\bin\index.js:62:12
at C:\Users\fabio.jose\AppData\Roaming\npm\node_modules\aws-sam-local\node_modules\go-npm\bin\index.js:51:9
at ChildProcess.exithandler (child_process.js:202:7)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:192:7)
at maybeClose (internal/child_process.js:890:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\fabio.jose\AppData\Roaming\npm-cache\_logs\2017-11-03T12_32_03_143Z-debug.log
Following fixed for me
pankajsamsung's "npm config" change above fixed it for my issue, thx
last solution worked for me in Windows bash environment
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
> [email protected] 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)
npm install -g go-npm then npm install -g aws-sam-local worked for me
pankajsamsung's fix worked for me as well
npm config set unsafe-perm=true
worked for me on mac os
npm config set unsafe-perm=true
worked for me on mac sierra too. Thanks @Rajjae
npm config set unsafe-perm=true
worked for me on ubuntu 17.10 too. Thanks @Rajjae
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
npm install -g go-npm then npm install -g aws-sam-local worked for me
worked for me on Ubuntu 16.04 LTS with
npm config set unsafe-perm=true
Confirm, I had issues both on my Ubuntu 16.04 LTS and on my Oracle Linux 7 VM.
Had to sort that out using:
npm config set unsafe-perm=true
After setting npm config set unsafe-perm=true and chowning my /usr/local/lib/node_modules directory to myself I can successfully sudo npm install -g.
$ node -v
v7.10.1
$ npm -v
5.8.0
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
npm config set unsafe-perm=true also worked for me
I have
npm -v
6.0.1
node -v
v8.11.1
But what does mean unsafe-perm?
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
Still required in 2019! npm config set unsafe-perm=true
@iceback We no longer support npm and is very much out of date.
New install instructions can be found here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
Thanks for picking up! Earlier I was chagrined to think that I had
missed a step in installing sam. I had followed the link you reference,
and today abortive installation had no influence on my problem.
You can see that problem at
https://forums.aws.amazon.com/thread.jspa?messageID=916550󟱆
On 9/18/19 4:24 PM, Jacob Fuss wrote:
>
@iceback https://github.com/iceback We no longer support npm and is
very much out of date.New install instructions can be found here:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-sam-cli/issues/66?email_source=notifications&email_token=AACY7PEFRJAR36MU5ZKREDDQKKTA5A5CNFSM4DXFWMLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7BUDVY#issuecomment-532890071,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACY7PBKPTK2LSFZUKBEWULQKKTA5ANCNFSM4DXFWMLA.
Most helpful comment
Following fixed for me
npm config set unsafe-perm=true