Nativescript-cli: Can't install latest 2.5.4 nativescript version

Created on 13 Apr 2017  路  2Comments  路  Source: NativeScript/nativescript-cli

Tell us about the problem

On mac with osx 10.11.6 el capitan, the command
sudo npm install -g nativescript

give an error EACCES

Verifying CocoaPods. This may take more than a minute, please be patient.
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "tns-ios" "--global" "false" "--ignore-scripts" "--production" "--save"
npm ERR! node v7.6.0
npm ERR! npm v4.1.2
npm ERR! path /Users/nemesix/.npm/tns-ios/2.5.0/package.tgz.126580686
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open '/Users/nemesix/.npm/tns-ios/2.5.0/package.tgz.126580686'
npm ERR! { Error: EACCES: permission denied, open '/Users/nemesix/.npm/tns-ios/2.5.0/package.tgz.126580686'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/Users/nemesix/.npm/tns-ios/2.5.0/package.tgz.126580686',
npm ERR! parent: 'nativescript-check-cocoapods' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/lib/node_modules/nativescript/nativescript-check-cocoapods117313-3025-17uyrrb.db924vx6r/npm-debug.log

on a folder which I have full control '/Users/nemesix/.npm
I've tried to create the tns-ios/2.5.0/package folders and restart the installation so
I got this reported error.

The installation goes on till the new error where I press enter to leave blank the email

Leave your e-mail address here to subscribe for NativeScript newsletter and product updates, tips and tricks:
? (press Enter for blank)
EACCES: permission denied, open '/Users/nemesix/.local/share/.nativescript-cli/user-settings.json'
Error: Unknown command 'post-install-cli'. Try '$ tns help' for a full list of supported commands.
at Errors.fail (/usr/local/lib/node_modules/nativescript/lib/common/errors.js:107:28)
at Errors.failWithoutHelp (/usr/local/lib/node_modules/nativescript/lib/common/errors.js:115:14)
at HtmlHelpService.readMdFileForCommand (/usr/local/lib/node_modules/nativescript/lib/common/services/html-help-service.js:108:22)
at HtmlHelpService.getCommandLineHelpForCommand (/usr/local/lib/node_modules/nativescript/lib/common/services/html-help-service.js:111:29)
at /usr/local/lib/node_modules/nativescript/lib/common/commands/help.js:25:50
at Function.settle (/usr/local/lib/node_modules/nativescript/node_modules/fibers/future.js:249:26)
at FiberFuture.wait (/usr/local/lib/node_modules/nativescript/node_modules/fibers/future.js:565:10)
at /usr/local/lib/node_modules/nativescript/lib/common/services/commands-service.js:49:55
at Function.settle (/usr/local/lib/node_modules/nativescript/node_modules/fibers/future.js:249:26)
at FiberFuture.wait (/usr/local/lib/node_modules/nativescript/node_modules/fibers/future.js:565:10)
Sending exception report (press Ctrl+C to stop).../usr/local/lib

Update:
after all i tried with tns doctor and all goes well

Please provide the following version numbers that your issue occurs with:

$ node --version
v7.6.0
$ npm --version
4.1.2

Please tell us how to recreate the issue in as much detail as possible.

question

Most helpful comment

Hey @gbonline ,
The problem is in fact a "feature" of npm. Whenever you use sudo npm install -g <something>, npm executes the operation and starts postinstall scripts of the package. However these postinstall scripts can do anything with your machine. As there are many, many packages in npm, you cannot be sure which of the packages are safe to be installed. For example I may create a package, that executes rm -rf / on postinstall. In order to protect you in this case (when sudo is used), npm executes the postinstall scripts with a special user called nobody. This user has limited permissions and cannot write files to your directories.
CLI's postinstall script is trying to verify your machine works correctly by verifying Cocoapods installation. In this case it needs write access to the npm cache (in your case /Users/nemesix/.npm), however the nobody user does not have such write access. That's why you see the errors on postinstall.
One more thing that has to be noted - even if postinstall script fails, the installation is successful and you can use CLI.
There are two ways to bypass the errors on postinstall:

  1. Execute sudo npm install -g nativescript --ignore-scripts - this will skip the postinstall step.
  2. Execute sudo npm install -g nativescript --unsafe-perm - this will allow execution of postinstall scripts with the sudo user.

Hope this clears it out. I believe you can use the CLI without issues at the moment, so I'm closing this thread. Feel free to contact us in case you still have problems or concerns.

All 2 comments

Hey @gbonline ,
The problem is in fact a "feature" of npm. Whenever you use sudo npm install -g <something>, npm executes the operation and starts postinstall scripts of the package. However these postinstall scripts can do anything with your machine. As there are many, many packages in npm, you cannot be sure which of the packages are safe to be installed. For example I may create a package, that executes rm -rf / on postinstall. In order to protect you in this case (when sudo is used), npm executes the postinstall scripts with a special user called nobody. This user has limited permissions and cannot write files to your directories.
CLI's postinstall script is trying to verify your machine works correctly by verifying Cocoapods installation. In this case it needs write access to the npm cache (in your case /Users/nemesix/.npm), however the nobody user does not have such write access. That's why you see the errors on postinstall.
One more thing that has to be noted - even if postinstall script fails, the installation is successful and you can use CLI.
There are two ways to bypass the errors on postinstall:

  1. Execute sudo npm install -g nativescript --ignore-scripts - this will skip the postinstall step.
  2. Execute sudo npm install -g nativescript --unsafe-perm - this will allow execution of postinstall scripts with the sudo user.

Hope this clears it out. I believe you can use the CLI without issues at the moment, so I'm closing this thread. Feel free to contact us in case you still have problems or concerns.

thanks a lot rosen-vladimirov for the satisfactory explanation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickIliev picture NickIliev  路  3Comments

PeterStaev picture PeterStaev  路  3Comments

kefahB picture kefahB  路  3Comments

farfromrefug picture farfromrefug  路  3Comments

MrCroft picture MrCroft  路  3Comments