There'due south a bit of a headache going around in respect to global npm permissions. For those of us working on Unix-based systems, it'due south non uncommon to come up across mistake messages complaining near your user permissions whenever installing new npm packages, especially when installing them globally.

If errors like the one below  await familiar, you're not lone:

            npm WARN checkPermissions Missing write access to /Users/toddbirchard/.npm-packages/lib/node_modules npm ERR! path /Users/toddbirchard/.npm-packages/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, admission '/Users/toddbirchard/.npm-packages/lib/node_modules' npm ERR!  { [Error: EACCES: permission denied, access '/Users/toddbirchard/.npm-packages/lib/node_modules'] npm ERR!   stack: npm ERR!    'Mistake: EACCES: permission denied, admission \'/Users/toddbirchard/.npm-packages/lib/node_modules\'', npm ERR!   errno: -thirteen, npm ERR!   code: 'EACCES', npm ERR!   syscall: 'access', npm ERR!   path: '/Users/toddbirchard/.npm-packages/lib/node_modules' } npm ERR! npm ERR! The operation was rejected by your operating organization. npm ERR! It is probable y'all do non accept the permissions to admission this file every bit the current user npm ERR! npm ERR! If you believe this might be a permissions issue, delight double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command once again as root/Administrator (though this is non recommended).  npm ERR! A complete log of this run can be constitute in: npm ERR!     /Users/toddbirchard/.npm/_logs/2019-05-05T20_36_45_642Z-debug.log          
NPM permission errors

This is a textbook case of beingness  trigger-happy with the sudo command. If y'all're installing npm every bit a user other than root, it's a bad idea to install Node + npm with the sudo command. If a non-root user installs these dependencies by escalating privileges via sudo, the installation will succeed indeed. However, nosotros've just created a scenario where the user in question does not have permission to modify global npm the user just installed (nor modify/install packages). When nosotros installed Node/npm with sudo, nosotros handed exclusive ownership to the root user. That would mean we'd have to specify sudo before every global package install, which is abrasive, but more chiefly unrealistic.

It gets worse. Npm packages which require postal service-install scripts to be run simply get impossible to install. Sometimes yous might exist able to become away with the following, merely only if the scripts aren't necessary:

            $ npm i -g [package-name] --ignore-scripts          
Install NPM bundle without running scripts post-execution

When the scripts are necessary, like in the case of node-sass, we're shit outta luck. Using the --ignore-scripts flag merely results in a broken install. Attempting to install using sudo looks similar this:

            $ sudo npm i -g node-sass  [sudo] countersign for todd: /home/todd/.npm-global/bin/node-sass -> /home/todd/.npm-global/lib/node_modules/node-sass/bin/node-sass          
Install node-sass globally

Uh oh....

            Unable to save binary /home/todd/.npm-global/lib/node_modules/node-sass/vendor/linux-x64-64 : { Mistake: EACCES: permission denied, mkdir '/home/todd/.npm-global/lib/node_modules/node-sass/vendor'     at Object.mkdirSync (fs.js:753:3)     at sync (/home/todd/.npm-global/lib/node_modules/node-sass/node_modules/mkdirp/index.js:71:13)     at Role.sync (/dwelling house/todd/.npm-global/lib/node_modules/node-sass/node_modules/mkdirp/index.js:77:24)     at checkAndDownloadBinary (/home/todd/.npm-global/lib/node_modules/node-sass/scripts/install.js:114:11)     at Object.<anonymous> (/abode/todd/.npm-global/lib/node_modules/node-sass/scripts/install.js:157:1)     at Module._compile (internal/modules/cjs/loader.js:689:30)     at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)     at Module.load (internal/modules/cjs/loader.js:599:32)     at tryModuleLoad (internal/modules/cjs/loader.js:538:12)     at Function.Module._load (internal/modules/cjs/loader.js:530:3)   errno: -13,   syscall: 'mkdir',   code: 'EACCES',   path: '/abode/todd/.npm-global/lib/node_modules/node-sass/vendor' }  > node-sass@4.12.0 postinstall /home/todd/.npm-global/lib/node_modules/node-sass > node scripts/build.js  Building: /usr/bin/node /home/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ '/usr/bin/node', gyp verb cli   '/habitation/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js', gyp verb cli   'rebuild', gyp verb cli   '--verbose', gyp verb cli   '--libsass_ext=', gyp verb cli   '--libsass_cflags=', gyp verb cli   '--libsass_ldflags=', gyp verb cli   '--libsass_library=' ] gyp info using node-gyp@3.8.0 gyp info using node@10.xv.ii | linux | x64 gyp verb command rebuild [] gyp verb control clean [] gyp verb make clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` succeeded python2 /usr/bin/python2 gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.fifteen gyp verb cheque python version .%due south.%s" % sys.version_info[:3];"` returned: %j gyp verb get node dir no --target version specified, falling back to host node version: ten.15.ii gyp verb control install [ '10.fifteen.2' ] gyp verb install input version string "ten.fifteen.2" gyp verb install installing version: 10.15.2 gyp verb install --ensure was passed, so won't reinstall if already installed gyp verb install version is already installed, need to check "installVersion" gyp verb got "installVersion" ix gyp verb needs "installVersion" 9 gyp verb install version is good gyp verb get node dir target node version installed: 10.15.ii gyp verb build dir attempting to create "build" dir: /dwelling/todd/.npm-global/lib/node_modules/node-sass/build gyp ERR! configure mistake gyp ERR! stack Mistake: EACCES: permission denied, mkdir '/home/todd/.npm-global/lib/node_modules/node-sass/build' gyp ERR! System Linux 4.15.0-43-generic gyp ERR! control "/usr/bin/node" "/domicile/todd/.npm-global/lib/node_modules/node-sass/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /domicile/todd/.npm-global/lib/node_modules/node-sass gyp ERR! node -v v10.15.2 gyp ERR! node-gyp -five v3.8.0 gyp ERR! not ok Build failed with error code: 1 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@iv.12.0 postinstall: `node scripts/build.js` npm ERR! Exit condition one npm ERR! npm ERR! Failed at the node-sass@4.12.0 postinstall script. npm ERR! This is probably non a trouble with npm. There is probable boosted logging output above.  npm ERR! A consummate log of this run tin can exist institute in: npm ERR!     /dwelling/todd/.npm/_logs/2019-05-05T20_52_06_518Z-debug.log          
NPM parcel installation error

Why does this happen? Because past default, the mail service-install scripts attempt to run as the current user. Since the electric current user doesn't have permissions to mess with packages installed globally, the installation ultimately fails. To fix this, we need to reinstall Node the correct way.

Reinstalling Node

I'm working under the assumption that nosotros're using Ubuntu or a Debian-based Linux distro. The first affair we need to practise is remove Node:

            $ apt remove node $ apt remove nodejs          
Uninstall Node

Verify that Node is gone:

            $ which node          
Cheque Node version

If a folder path is returned by the above, nuke it. That should leave the states ready for a fresh install.

Since we're on a Debian system, nosotros demand to install Node via Nodesource. I'd recommend running this in the /tmp binder, or wherever you lot like to dump things saved from the cyberspace:

            $ curl -sL https://deb.nodesource.com/setup_10.ten | sudo -E bash - $ apt-get install -y nodejs          
Install Node from source

Now would be a good fourth dimension to get the latest npm as well:

            $ npm i -m npm@latest          
Update NPM

When the installation is complete, check to see if everything worked:

            $ node -v > v10.15.2          
Check Node version
            $ npm -v >> vi.9.0          
Check NPM version

Create a New Global NPM Directory

With Node reinstalled, we can motility on to creating and configuring a new directory to agree our global npm modules. You tin name this what you want, only it'due south generally recommended to name this npm-global or something of the sort. Don't use sudo!

            $ mkdir ~/.npm-global          
Create a new home for global NPM modules

At present we can configure npm to recognize this folder:

            $ npm config set prefix '~/.npm-global'          
Configure NPM

Side by side, nosotros demand to add together this to our PATH. This should go in ~/.bashrc or ~/.bash_profile, depending on which you utilise:

            $ echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc $ source ~/.bashrc          
Recognize new NPM binder on starup

You Did Skillful

That should practise information technology! From now on, remember to devious abroad from using sudo when installing Node, npm, or fifty-fifty modifying npm packages. The npm documentation explicitly recommends against this, but it'due south all practiced. Nosotros all make mistakes.