Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sudo npm install fails #66

Closed
sanathkr opened this issue Aug 16, 2017 · 37 comments
Closed

sudo npm install fails #66

sanathkr opened this issue Aug 16, 2017 · 37 comments
Assignees
Labels

Comments

@sanathkr
Copy link
Contributor

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
@sanathkr sanathkr self-assigned this Aug 16, 2017
@sanathkr
Copy link
Contributor Author

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.

@mhart
Copy link
Contributor

mhart commented Aug 20, 2017

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: npm/npm#17851

@sanathkr
Copy link
Contributor Author

It happens on npm 2 actually, whatever is bundled with Node 4.3.0

@mhart
Copy link
Contributor

mhart commented Aug 20, 2017

Ah, yeah, I should've spotted that from the install log – ok, probably not related then!

@PaulMaddox
Copy link
Contributor

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() ?

@georgmao
Copy link

georgmao commented Aug 21, 2017

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.

@PaulMaddox
Copy link
Contributor

@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.

@georgmao
Copy link

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/

@aniecki
Copy link

aniecki commented Aug 22, 2017

I have the same issue:

aws-sam-local@0.2.0 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)

@mhart
Copy link
Contributor

mhart commented Aug 22, 2017

Might be worth adding this to the documentation?

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

@mhart
Copy link
Contributor

mhart commented Aug 22, 2017

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

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

@georgmao
Copy link

yeah looks good to me.

PaulMaddox added a commit that referenced this issue Aug 22, 2017
@adoniscyp
Copy link

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

did the trick from me. Thanks mhart

@lurym
Copy link

lurym commented Aug 29, 2017

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

@jan-molak
Copy link

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.

@keisetsu
Copy link

keisetsu commented Oct 10, 2017

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!

@jhovell
Copy link

jhovell commented Oct 24, 2017

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! aws-sam-local@0.2.2 postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the aws-sam-local@0.2.2 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! aws-sam-local@0.2.2 postinstall: `go-npm install`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the aws-sam-local@0.2.2 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

@fabiorogeriosj
Copy link

In windows I have the same error:

C:\WINDOWS\system32>npm install -g aws-sam-local

> aws-sam-local@0.2.2 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! aws-sam-local@0.2.2 postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the aws-sam-local@0.2.2 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

@pankajsamsung
Copy link

Following fixed for me

npm config set unsafe-perm=true

@contractorwolf
Copy link

pankajsamsung's "npm config" change above fixed it for my issue, thx

@santhosh-v
Copy link

last solution worked for me in Windows bash environment

@johnwebbcole
Copy link

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)

@hloughrey
Copy link

hloughrey commented Dec 10, 2017

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

@nwkeeley
Copy link

pankajsamsung's fix worked for me as well

@Rajjae
Copy link

Rajjae commented Dec 18, 2017

npm config set unsafe-perm=true

worked for me on mac os

@lancha90
Copy link

lancha90 commented Dec 20, 2017

npm config set unsafe-perm=true

worked for me on mac sierra too. Thanks @Rajjae

@orleibicheski
Copy link

npm config set unsafe-perm=true
worked for me on ubuntu 17.10 too. Thanks @Rajjae

@Cnly
Copy link

Cnly commented Jan 6, 2018

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: nodejs/node-v0.x-archive#3911

@cjokinen
Copy link

cjokinen commented Jan 9, 2018

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

@titogeorge
Copy link

worked for me on Ubuntu 16.04 LTS with

npm config set unsafe-perm=true

@lfdesousa
Copy link

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

@crabmusket
Copy link

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

@neohunter
Copy link

neohunter commented May 13, 2018

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?

@bisw
Copy link

bisw commented Jul 25, 2018

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

@iceback
Copy link

iceback commented Sep 18, 2019

Still required in 2019! npm config set unsafe-perm=true

@jfuss
Copy link
Contributor

jfuss commented Sep 18, 2019

@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

@iceback
Copy link

iceback commented Sep 18, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests