Ionic 2 - Error: EACCES: permission denied in installation on Ubuntu 12.04LTS

微笑、不失礼 提交于 2019-12-12 05:17:31

问题


I'm getting the following error while installing ionic on ubuntu 12.04 LTS following instructions in http://ionicframework.com/docs/v2/getting-started/installation/

Commands used

install nodejs 6.x

cookbook$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
cookbook$ sudo apt-get install -y nodejs
cookbook$ node -v
v6.9.1
[~]
cookbook$ npm -v
3.10.8
[~]

install ionic per instructions

cookbook$ npm install -g ionic cordova



+-- readable-stream@1.0.34 
| +-- core-util-is@1.0.2 
| +-- inherits@2.0.3 
| +-- isarray@0.0.1 
| `-- string_decoder@0.10.31 
`-- setimmediate@1.0.5 

npm ERR! Linux 3.8.0-29-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "ionic" "cordova"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/lib/node_modules' }
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!     /home/cookbook/npm-debug.log
[~]

The error message suggests to try running this command again as root/Administrator.

What is the right way to go about this ?

similar issue on windows 10 here


回答1:


Do not use sudo, it will bring more problems on the long term. The following guide explains it perfectly: (Its for OSX but applies the same)

https://johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/




回答2:


Tried different suggestions from different references.

suggestion 1 from here - didn't work

This still gave the same error EACCES: permission denied

suggestion 2 from here - this worked

cookbook$  npm config get prefix
/usr
[~]
cookbook$ 

so this is issue and npm's recommendation is to change npm's default directory to another directory

Steps are as follows

  1. Make a directory for global installations:

    mkdir ~/.npm-global

  2. Configure npm to use the new directory path:

    npm config set prefix '~/.npm-global'

  3. Open or create a ~/.profile file and add this line:

    export PATH=~/.npm-global/bin:$PATH

  4. Back on the command line, update your system variables:

    source ~/.profile

After this ionic installation with cookbook$ npm install -g ionic cordova got completed without any errors.

cookbook$ ionic -v
--------------------------------
cordova -v******************************************************
 Dependency warning - for the CLI to run correctly,      
 it is highly recommended to install/upgrade the following:     

 Please install your Cordova CLI to version  >=4.2.0 `npm install -g cordova`

******************************************************
2.1.4

[~]
cookbook$ cordova -v
? May Cordova anonymously report usage statistics to improve the tool over time? Yes

Thanks for opting into telemetry to help us improve cordova.
6.4.0
[~]
cookbook$ 



回答3:


Try with sudo:

sudo npm install -g ionic cordova


来源:https://stackoverflow.com/questions/40340871/ionic-2-error-eacces-permission-denied-in-installation-on-ubuntu-12-04lts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!