Recently, while installing cordova npm package using $sudo npm install -g cordova, I came across the following error on my MacOS.

npm ERR! tar.unpack untar error /Users/xxxx/.npm/cordova/6.2.0/package.tgz
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "cordova"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! path /usr/local/lib/node_modules/cordova
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cordova'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/cordova']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/cordova',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/cordova',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:82:15)' ] }
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!     /Users/xxxxx/npm-debug.log

In a nutshell, it was asking me to run this command again as root/Administrator. A quick search on internet made me run the following command to fix the permission issue.

sudo chown -R $USER /usr/local

Then install cordova without the sudo command.

npm install -g cordova

Although, I received the following warning, the install went through successfully without any error.

npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue