Reputation: 13910
I am trying to start an angular web app with yeoman but I get permission issue when trying to install the new generator. I can bypass and install generator with sudo but then I get the permission errors when running
**yo** angular
I deduce its because its trying to access npm modules that are global which the current user doesnt have permissions for, and I cant run Yo with sudo. I have done a lot of google searches and they all involve some type of hack with the NODE_PATH in the .bashrc or moving the node modules to the home directory. Has anyone found a simple solution for this issue.
Below is my problem in screenshots:
yo installs fine
when i try to install the generator without sudo complains..
install with sudo passes.
then finally when I try to run yo angular it breaks.. I believe its because yo runs as user and I have installed everything with sudo privileges. How can I get past this?
Upvotes: 0
Views: 135
Reputation: 219
The reason it breaks, I guess, is because the whole directory tree was created as super-user.
The hacks you mentioned about using NODE_PATH
and the home directory are not hacks. They exist for this same very reason. To tell node where to look for packages. And .bashrc
is the place where you are supposed to change this kind shell variables.
Say you added ~/.node_modules
to you NODE_PATH
, then you can install all "global" in there. You could also change the permissions on /usr/local
. But on linux world that is not recommended.
I also strongly recommend in not using global install with npm. Using -g and npm link
is handy when developing but you shouldn't count on them. You can introduce subtle bugs in your code when you forget to add a package on you package.json
but it is installed globally.
Instead of installing it globally, you can find all the packages executable on ./node_modules/.bin/
directory.
But lets say you don't want to be typing ./node_modules/.bin/yo
all the time, you could create an alias on your .bashrc
.
alias yo="$PWD/node_modules/.bin/yo"
and it would work like expected, and if there is no yo package installed, you get an error.
Upvotes: 1