Cannot run iOS. You cannot run cocoapods as root

Why am I using root? because the run script reuqires ng command first which says premission denied, so I said sudo. then cocoapods give me this error. Or so I think. Here is the more speicfic error:

An unhandled exception occurred: EACCES: permission denied, unlink '/Users/darren/.Trash/IonicTest/IonicTest/www/common.js'
See "/private/var/folders/bt/nv94cvpx26xfz74hhp808xy80000gn/T/ng-TOKRcl/angular-errors.log" for further details.
[ERROR] An error occurred while running subprocess ng.

but when running with sudo the above error goes away only to get the cocopod error

using capacitor. android runs looks fine, tho i also had to use root.

Never run anything involving Ionic development as root.


Once you break this rule, you are going to cause endless permission headaches and it becomes virtually impossible to know what exactly to clean up.

I literally would consider reinstalling the entire OS from scratch after you’ve done this.

nvm is a great way to easily install a Node.js ecosystem in your home directory, and should also eliminate most, if not all, of the typical triggers that seem to cause people to start blindly stomping all over things with sudo.

bruh. literally all SO tutorials on npm issues smacks a sudo on there. i cant reinstall the os dude.

currently i think i uninstall npm and node modules, and use homebrew?

I’m not in the mood to trawl through SO looking for counterexamples, so I’ll just say this: I have no idea where npm itself (to say nothing of the zillions of arbitrary scripts it downloads from the Internet and runs with the permissions of whatever npm is being run) writes files. I don’t care to find out. It might change tomorrow. I shouldn’t have to care.

Once you run a program that writes and modifies arbitrary files in places you have no clue about as superuser, no regular user can clean that up (and hey, maybe it installed a rootkit or some ransomware while it was at it. Sleep tight.). So you have to go on a massive hunt (as root, which presents even more opportunities for disaster) and chmod / chown operation.

But don’t take my word for it. You’ve run headfirst into the problem yourself. You have files in your home directory and in npm caches all over the place that only root can touch. I have never used sudo with any Node.js work (including Ionic stuff) in the last 5 years since I discovered nvm.

ok. gonna reinstall my os. see u in a bit

1 Like

should I install homebrew with sudo?

I’ve never used homebrew, but a glance at its documentation suggests that it writes to /usr/local/, so you would have to. The bigger question would be “should I install homebrew?”, and my answer would be “if you want to, but not in order to do Ionic development”. Just install nvm, and then your entire Node.js world will live in your home directory.

1 Like

I have to download gcloud and stuff later down the road. So home brew with sudo is ok? Ok here I go!

I got homebrew and node installed! was able to install angular cli and ionic cli globally without asking for premission… unless i am in root xD. But my cmd is darren@Darrens-MacBook-Pro ~ % , it looks like user. if i done everything right you probably saved me big time from future screw ups

Congratulations. Hope things go smoothly for you in the future. Incidentally, in any POSIX system (I think) you can always type either whoami or id to figure out that existential question.