Configure Ubuntu to enable the execution of npm without sudo

Node.js Package Manager (NPM) , is an is an online repository for the publishing of open-source Node.js projects, and a command-line utility for interacting with said repository that aids in package installation, version management, and dependency management. Essentially what this tools enables you to do is easily and quickly make use of the plethora of nodejs packages being developed on a daily basis. NPM enables the community to share and contribute to reusable javascript code libraries to help others with common software development problems.

Why executing NPM as root is a bad idea

Although the npm is effectively community managed and for the most part is a great resource. The main drawback is that not everybody in the community can be trusted. There may be some members of the community that may publish a script for nefarious reasons. it is because of this you don’t necessarily want to give any script you download from the internet root permissions to your machine. Typically you would want to have NPM execute as user with a reduced permission level.

NB : Running npm as your user account also may not be the best solution, as typically the files that contain sensitive information are typically in your user account folders

Download
 

Gary Woodfine

Freelance Full Stack Developer at threenine.co.uk
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.

Latest posts by Gary Woodfine (see all)

Affiliate Disclaimer

Disclosure: Please note that some of the links included in the blog posts are affiliate links, which means I will earn a commission if you decide to make a purchase.

I only include affiliate links to products, services and companies that I have personal experience and have actually used. I only recommend them because they are helpful and useful, not because of the small commissions I make if you decide to buy something.

Please do not spend any money on these products unless you feel they are relevant, suitable and will help you achieve your goals.

Buying anyone of these products and the commisions earned will not make me an overnite multi millionaire, but they will help to cover the hosting costs and compensate for the countless hours and effort I put in to create meaningful and valuable free content I provide to help others succeed.

You've also undoubtedly noticed that I also use various advertising networks - unless of of course you're using an Ad blocker, this is also an attempt to reduce my monthly deficit I experience in providing free relevant, valuable and on occassion insightful content for the benefit of others.

I only really make some money if people click on the ads, unless of course you consider 1c per 1000 impressions real money!

Bear in mind just how many impressions I need to make before I can cover my £20 hosting costs a month!

If you are using an adblocker and guilt stricken you can of course donate using any of the buttons below, but I won't be holding my breath.

Buy me a coffeeBuy me a coffee

π