Yeoman Permission issue in vagrant when installed globally - node.js

Today I started with exploring yeoman. I am using Vagrant with a clean Ubuntu 12.04 box. The box is provisioned using this gist that I created and update with the steps I am performing inside vagrant.
So I have installed node globally. When I create a new map ~/yo-demo && cd yo-demo and then type yo I get to see yeoman. But I try to install a generator I get a error:
[Error: EACCES, mkdir '/usr/lib/node_modules/generator-webapp']
This is because node_modules is not vagrant's but it's a root (user) folder. So I can fix this with sudo chown -R vagrant:vagrant /usr/lib/node_modules. But I am not sure if this is the best thing to do.
Is there another way of fixing this? I think I could install it locally, but then again I can't use the yo command from within any folder (That's what I read, but not sure? I havent tested it).
I am soon going to have a VPS and while I wont install yo on there I would probably install other things like node. What would be the preferred location on a vps? Locally or globally?

Related

Ionic, npm and cordova commands all require sudo to work

The sudo, by the looks of what I have seen in some forums, is why I am getting an error when running sudo ionic emulate ios in this post New to ionic - can’t build for ios (9) on El Capitan, and sudo ionic is required, deprecated npmconf. (I am running El Capitan btw).
Whenever I need to use an ionic, npm, or cordova command, I always have to put sudo in front of it otherwise I get a "bash command not found" error. I have tried to use this fix https://www.npmjs.com/package/npm-sudo-fix but it doesn't work. This is what happens in the log:
Dylans-MBP:Ionic Projects Dylan $ sudo npm install -g npm-sudo-fix
Password:
/usr/local/bin/npm-sudo-fix -> /usr/local/lib/node_modules/npm-sudo-fix/index.js
npm-sudo-fix#0.1.3 /usr/local/lib/node_modules/npm-sudo-fix
└── spawny#0.0.1 (cmdify#0.0.4)
Dylans-MBP:Ionic Projects Dylan$ sudo npm-sudo-fix
chown: /users/root/.npm: No such file or directory
Edit (28 August 2018):
I wrote this post and answer many years ago when I was not very familiar with the terminal. Now that I am more experienced, I can recommend the better solution. It is good practice to avoid unnecessary usages of sudo.
I believe the problem is caused by installing node JS from the installer from the node JS website. This version of node JS seems to write various files in the filesystem as root, potentially (and unnecessarily) causing global packages to require root permissions to be installed.
The ideal solution would be to completely remove node JS, that was installed from the node JS installer from the website, from your machine (see https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/). Then install node from a commandline package manager, such as homebrew.
Original Answer (2016)
Finally came up with a solution by playing with the permissions! Hopefully I didn't stuff up anything. (I am a terminal noob btw.) Anyway, here's the solution.
Run this code here in the terminal (you may or may not have to run cd .. before hand)
sudo chown -R $USER /usr/local/
This changes the permissions of every thing inside the local folder (hence the -R which means recursive). (I found this line somewhere in the ionic forums).
Now, you have to reinstall cordova and ionic
sudo npm install -g cordova
sudo npm install -g ionic
For me anyway, after I do this, I can type ionic and not get any errors. I get this in the terminal if I run cordova though.
/usr/local/lib/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:53
throw err;
^
Error: EACCES: permission denied, open '/Users/Dylan/.config/configstore/update-notifier-cordova.json'
You don't have access to this file.
What I did to fix this was do this (after opening up a new terminal window):
sudo chown -R $USER Dylan
(Dylan is my user folder; replace it with yours. Also, you may have to do a cd .. before running that line And that fixes the permissions for that config file. Now running cordova works without errors! Woot! That error might come back though, so you have to run that line of code again.
Hope this helps somebody!

Permissions Denied in Terminal

So I am a little new to working in the terminal and trying to set up yo and a localhost environment. No matter what I do it keeps throwing a permissions denied error. I have installed node and npm already and when I run the yo install
npm install -g yo bower grunt-cli gulp i get this error message. My buddy and I have tried so many different things to fix this but we cant get anywhere. I can access and run using sudo but I need to actually have the permissions to get this working. Help please?
I am sorry if that is not detailed enough, I am new to working in the terminal and may not know entirely what I am doing. If all else fails I was going to reset my desktop to factory settings and start over with setting my users and groups.
Screenshot of errors Here
sudo chown -R `whoami` /usr/local
or
npm install npm -g
...will do the trick.
You're not the first one to experience those problems and they are (finally) actively addressed in npm#3.X.X

How can I get the slc command to work on Ubuntu?

I have installed Strongloop using npm install -g strongloop on my Ubuntu 14.04 server. The slc command does not work. It says
The program 'slc' is currently not installed. You can install it by typing:
sudo apt-get install heimdal-multidev
How can I get it to run the Strongloop CLI instead of looking for this package? I have added this to my PATH and it still doesn't work. Any ideas?
Other Strongloop commands, like sl-build work and strongloop is listed in npm list -g.
Ubuntu 14 with node.js 4.1.2
By default somehow slc is not created or not added to PATH.
I solved this problem by adding symlink:
sudo ln -s /usr/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
A soft link named slc should have been created at /usr/local/bin which will point to strongloop binary.
Please verify if the following exists.
/usr/local/lib/node_modules/strongloop/bin/slc
If no, then strongloop did not get installed successfully, otherwise verify the existence of the softlink slc at /usr/local/bin/.
/usr/local/bin/slc -> /usr/local/lib/node_modules/strongloop/bin/slc
If yes, then /usr/local/bin needs to be added to the $PATH, otherwise create the softlink and verify that /usr/local/binin $PATH.
Looks like the Node installation that optionally comes with a Digital Ocean Droplet installs to a different location that's not in $PATH. I'm pretty sure that was the issue. Anyways, I fixed it by spinning up a server without Node pre-installed and followed this guide. Just use npm install -g strongloop instead of strong-cli because the latter has been deprecated.
Ubuntu 14.04 with node.js 4.4.2 (LTS) :
The installation of strongloop was done without any errors but slc was not added to the PATH. I solved this problem by adding the symlink:
sudo ln -s /usr/local/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
Actually i am not sure my case matches with yours but i want to share my experience. i got the same message anyway.
I realized that i had changed prefix of global packets before. Then i checked prefix with the following command.
$ npm config get prefix
/home/myUser/.node_modules_global
Then i added the path to PATH variable (but .profile, .bash_profile files will be better) in active command line window and problem solved.

Hubot installation error where --create does not create a directory

I'm trying to heroku-deploy a hubot application (into Slack, if that matters). I'm developing locally on Ubuntu 14.04. I am closely following these instructions.
Here are my steps...
sudo apt-get install node npm
sudo npm install -g hubot coffee-script
hubot --create myrobot
However, nothing at all is created, there is no myrobot directory---and there is no statement of error. Honestly, I'm not even sure where to look for debugging information.
It doesn't make a difference, but is good practice to be doing all this within a cloned git:hubot-slack directory?
The issue was resolved by creating a symlink from nodejs to node.

yeoman permission issue with nodejs and angular

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?
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.

Resources