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


Gary Woodfine

Freelance Full Stack Developer at
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.