{"id":7311,"date":"2016-11-01T16:48:55","date_gmt":"2016-11-01T20:48:55","guid":{"rendered":"http:\/\/www.ericfeminella.com\/blog\/?p=7311"},"modified":"2024-04-01T23:14:11","modified_gmt":"2024-04-02T03:14:11","slug":"npm-root-permissions","status":"publish","type":"post","link":"https:\/\/www.ericfeminella.com\/blog\/2016\/11\/01\/npm-root-permissions\/","title":{"rendered":"NPM &#038; Root Permissions"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/img\/articles\/npm-root-permission.png\"\/><\/p>\n<p>When dealing with <a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">NPM<\/a> Permissions, often times it can be tempting to resort to installing modules as root (<code>sudo<\/code>), especially when under tight time constraints; where troubleshooting such issues will only serve to delay your progress. <\/p>\n<p>Admittedly, I have been guilty of this more often than I care to admit. That said, being as I always have the <a href=\"https:\/\/pragprog.com\/the-pragmatic-programmer\/extracts\/software-entropy\" target=\"_blank\" rel=\"noopener noreferrer\">Broken Windows Theory<\/a> in the back of my mind, I knew this workaround needed to be resolved as soon as I had a moment to dig into it a bit more.<\/p>\n<p>Previously, I had followed the instructions from <a href=\"https:\/\/docs.npmjs.com\/getting-started\/fixing-npm-permissions\" target=\"_blank\" rel=\"noopener noreferrer\">docs.npmjs<\/a>; however, they focus more on installations of global dependencies, rather than local dependencies. Fortunately, after a few quick searches, it became apparent that by simply changing permissions to the <i>~\/.npm<\/i> directory, this issue could easily be resolved as, all that is needed is to change the owner of the <i>~\/.npm<\/i> directory to the current user (as opposed to root).<\/p>\n<p>To do so, simply run the following:<\/p>\n<pre class=\"lang:js decode:true \" >sudo chown -R $(whoami) ~\/.npm<\/pre>\n<p>Likewise, you can use your username explicitly; e.g.:<\/p>\n<pre class=\"lang:js decode:true \" >sudo chown -R efeminella ~\/.npm<\/pre>\n<p>And with that, the issue can safely be resolved, allowing you to run <code>npm install<\/code> as expected without having to fallback to using <code>sudo<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When dealing with NPM Permissions, often times it can be tempting to resort to installing modules as root (sudo), especially when under tight time constraints; where troubleshooting such issues will only serve to delay your progress. Admittedly, I have been guilty of this more often than I care to admit. That said, being as I always have the Broken Windows&#8230; <a class=\"read-more\" href=\"https:\/\/www.ericfeminella.com\/blog\/2016\/11\/01\/npm-root-permissions\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":8582,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[201],"tags":[293,292,294,295],"class_list":["post-7311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-quick-tips","tag-node","tag-npm","tag-npm-permissions","tag-sudo"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.ericfeminella.com\/blog\/wp-content\/uploads\/2016\/11\/npm-root-permission.png?fit=718%2C320&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/7311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/comments?post=7311"}],"version-history":[{"count":1,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/7311\/revisions"}],"predecessor-version":[{"id":8583,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/7311\/revisions\/8583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media\/8582"}],"wp:attachment":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media?parent=7311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/categories?post=7311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/tags?post=7311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}