{"id":1728,"date":"2016-09-17T10:41:20","date_gmt":"2016-09-17T13:41:20","guid":{"rendered":"https:\/\/danillolima.com\/en\/?p=1728"},"modified":"2016-09-17T10:41:20","modified_gmt":"2016-09-17T13:41:20","slug":"how-to-fix-permissions-on-globally-installing-npm-packages-on-linux","status":"publish","type":"post","link":"https:\/\/danillolima.com\/en\/npm\/how-to-fix-permissions-on-globally-installing-npm-packages-on-linux\/","title":{"rendered":"How to fix permissions on globally installing npm packages on linux"},"content":{"rendered":"<p>Is common have packages that works globally, they make the work more easy in some ways, provide functionalities, et al..<\/p>\n<p>The difference in npm packages that are installed <strong>globally and locally<\/strong> is that you will setup a package like a program avaliable by a CLI(Command Line Interface)\u00b9, this require permissions to write in some directories that the npm normally don&#8217;t has.<\/p>\n<p>When you try install some globally package(using the -g):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">npm install -g &lt;package&gt;<\/pre>\n<p>You can face errors and warnings like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">npm WARN checkPermissions Missing write access to \/usr\/lib\/node_modules\nnpm ERR! path \/usr\/lib\/node_modules\nnpm ERR! code EACCES\nnpm ERR! errno -13\nnpm ERR! syscall access\nnpm ERR! Error: EACCES: permission denied, access '\/usr\/lib\/node_modules'\nnpm ERR!  { [Error: EACCES: permission denied, access '\/usr\/lib\/node_modules']\nnpm ERR!   stack:\nnpm ERR!    'Error: EACCES: permission denied, access \\'\/usr\/lib\/node_modules\\'',\nnpm ERR!   errno: -13,\nnpm ERR!   code: 'EACCES',\nnpm ERR!   syscall: 'access',\nnpm ERR!   path: '\/usr\/lib\/node_modules' }\nnpm ERR! \nnpm ERR! The operation was rejected by your operating system.\nnpm ERR! It is likely you do not have the permissions to access this file as the current user\nnpm ERR! \nnpm ERR! If you believe this might be a permissions issue, please double-check the\nnpm ERR! permissions of the file and its containing directories, or try running\nnpm ERR! the command again as root\/Administrator (though this is not recommended).\n\nnpm ERR! A complete log of this run can be found in:<\/pre>\n<p><!--more-->This is a EACESS error that can be fix by creating a directory for global installations, setting npm to config the directory and add the npm-global\/bin to the path of OS(Operating System).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">mkdir ~\/.npm-global\nnpm config set prefix '~\/.npm-global'\nexport PATH=~\/.npm-global\/bin:$PATH ### Add this to the end of the file ~\/.profile\nsource ~\/.profile<\/pre>\n<p>This can be found in:\u00a0<a href=\"https:\/\/docs.npmjs.com\/getting-started\/fixing-npm-permissions\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.npmjs.com\/getting-started\/fixing-npm-permissions<\/a>.<\/p>\n<p><strong>Don&#8217;t use sudo<\/strong> to install packages globally, this is a unsafe choice because npm install can run arbitrary scripts, you can get more EACESS errors later, locally you are creating a directory that only can be managed with sudo permissions, don&#8217;t make this.<\/p>\n<ol>\n<li>This can be conceptually wrong<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Is common have packages that works globally, they make the work more easy in some ways, provide functionalities, et al.. The difference in npm packages that are installed globally and locally is that you will setup a package like a program avaliable by a CLI(Command Line Interface)\u00b9, this require permissions to write in some directories [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1728","post","type-post","status-publish","format-standard","hentry","category-npm"],"_links":{"self":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts\/1728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/comments?post=1728"}],"version-history":[{"count":0,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/posts\/1728\/revisions"}],"wp:attachment":[{"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/media?parent=1728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/categories?post=1728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danillolima.com\/en\/wp-json\/wp\/v2\/tags?post=1728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}