Friday, January 18, 2019

How to resolve "Missing write access to /usr/local/lib/node_modules" when install expo-cli?

Software Required
- NPM version 6.4.1

Problems
  • I'm exploring React and try to install expo-cli by executing command "npm install -g expo-cli", error as shown below is displayed
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR!   stack:
npm ERR!    "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
  • I know this is a common problem and solutions is available over the internet, I think this is necessary to write a small little note for my own jot down.
Steps
  • Run command below to resolve the permission problem
$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ export PATH=~/.npm-global/bin:$PATH
$ source ~/.profile
  • Run command below to install expo-cli
$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ export PATH=~/.npm-global/bin:$PATH
$ source ~/.profile
$ npm install -g expo-cli
  • You are good to create your React project now.

No comments: