node.js - Run npm as superuser, it isn't a good idea? -
i'm getting errors npm
while trying install/update packages without su permissions on linux.
the easy way solve problem execute sudo npm install <package>
, i'm not sure if idea.
best way become owner of .npm
folder, found stackoverflow's questions , blog posts.
my question is: why run npm
su isn't idea?
running npm
super user has risk of running untrusted code super user can potentially mess entire system. running npm
unprivileged user has risk of running code less privileges , won't able mess entire system - own files (which can equally bad, depending on how @ it).
what , recommend install node in home directory instead of globally on system if it's own computer. way don't have run sudo
or su
npm
or make install
of node itself.
i run lot of versions of node compile sources different switches , convention use install node in versioned directories, either globally in /opt
(but need sudo
) or locally in home directory in ~/opt
.
i this:
wget https://nodejs.org/dist/v7.1.0/node-v7.1.0.tar.gz tar xzvf node-v7.1.0.tar.gz cd node-v7.1.0 ./configure --prefix=$home/opt/node-v7.1.0 make && make test && make install
then create symlink ~/opt/node
pointing ~/opt/node-v7.1.0
, have:
path="$home/opt/node/bin:$path"
in .profile
or .bashrc
.
that way don't have run super user installing node or running npm.
as bonus can switch default node version changing symlink, , @ time can run other version if change path or run node full path ~/opt/node-v7.0.0/bin/node
.
i explained installation process in more detail in other answers:
- node 5.5.0 installed node -v fetches “v4.2.1” on os x & homebrew?
- nodejs api external deps in other language
i don't want go detail here since answer why running npm
superuser not idea - installation process 1 solution not have run npm
superuser.
other options of setting npm permissions avoid running superuser described in fixing npm permissions in npm docs (thanks ryanzim pointing out in comments).
Comments
Post a Comment