1

I'm trying to install a package using npm install -g PACKAGE_NAME but it is throwing the following error.

npm http GET https://registry.npmjs.org/ionic
npm http 304 https://registry.npmjs.org/ionic
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/ionic',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/lib/nodejs/fstream/lib/writer.js:171:23',
npm ERR!      '/usr/lib/nodejs/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

Also when I tried sudo npm install -g PACKAGE_NAME , it executed silently but the package was not installed.

$ sudo npm install -g ionic
npm http GET https://registry.npmjs.org/ionic
npm http 304 https://registry.npmjs.org/ionic
/usr/local/bin/ionic -> /usr/local/lib/node_modules/ionic/bin/ionic
ionic@1.7.13 /usr/local/lib/node_modules/ionic
xarvis@xarvis:~/songhop/self$ ionic
/usr/bin/env: node: No such file or directory

Also As stated in an answer on stack overflow I've give write access in node_module directory using sudo chown -R $USER node_modules.

Satwik
  • 1,281
  • 4
  • 18
  • 31

1 Answers1

1

The first error says you are not root. If you want to add node modules as user avoid -g (global) in your npm command.

The second one is saying that it cannot find node. You need to do a symbolic link from nodejs to node while installing nodejs in ubuntu as:

sudo ln -s /usr/bin/nodejs /usr/bin/node

To test your node installation, type in terminal node -v to see the node version number.

Tonechas
  • 13,398
  • 16
  • 46
  • 80