npm ERR! Please try running this command again as root/Administrator

npm install express -g  - Here is another solution for one more nasty error while installing express via npm package manager, matter of fact occurring not only for express but other node packages too.

You are most likely to get that error if using mac or linux. Main reason obviously is that npm (Node Package Manager) requires “sudo” (root/Administrator) privileges. Running it as a regular user you don’t really have a write access to listed directory  /usr/local/lib/node_modules therefore new directory ‘express’ can not be created at that location.

There is more than one method to go about this.

 

Method 1:  You can simply sudo yourself and run below command

sudo npm install express -g

Disadvantage is that you will have to sudo yourself every time you want to install package with “-g” (global) option.

 

Method 2: To avoid that you can add yourself to the group that npm belongs to and so you can check the group running:

and then as explained in this post you could do something like

Big disadvantage of that method is that it will give you access to everything that “desired group” has access to. You don’t wont that, right?

 

Method 3: It would be better to get access to npm more permanently without the need of typing a password every time you run sudo npm.

To do that can modify /etc/sudoers file for example. Entry we are about to add should follow its general syntax:

And so before you proceed login as root

And then execute below command replacing “your_user_name” with your user name

Now CTRL-D to logout and CTRL-D one more time. You need to reopen terminal and try to install your express (or any other node package) with

 

…and voilà! There you have it.

 

Freelance developer, IT enthusiast, blogger with entrepreneurial spirit and passion for making games

Tagged with:
, , , , , , , ,
Posted in
Technical
Categories