1

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

Community
  • 1
  • 1
user3206440
  • 3,707
  • 9
  • 48
  • 93

3 Answers3

3

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$ 
Community
  • 1
  • 1
user3206440
  • 3,707
  • 9
  • 48
  • 93
  • The alternative method in suggestion 2 also works fine. In GNU/Linux just add `NPM_CONFIG_PREFIX=~/.npm-global` in `~/.bashrc` file and ignore steps 2 to end in suggestion 2. – Pedram Jan 17 '21 at 14:15
2

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/

Franco
  • 746
  • 1
  • 8
  • 21
0

Try with sudo:

sudo npm install -g ionic cordova
manzapanza
  • 5,463
  • 4
  • 36
  • 44
  • is this recommend way to do it ? does it have any side effects ? Ionic documentation doesn't seem to say this. – user3206440 Oct 31 '16 at 11:14
  • @Antonis - can you add reference / reason for running this as `sudo` – user3206440 Oct 31 '16 at 13:40
  • Ionic [does not recommend using sudo](https://ionicframework.com/docs/developing/tips#resolving-permission-errors) because "it can lead to further complications." – Pedram Jan 17 '21 at 13:53