Search code examples
macosionic-frameworkionic4

Why do I always need SUDO


I have a Mac Book Pro and my operation system MacOS. I am coding with ionic and I have to use all command with SUDO. I don't want to do this.

ionic cordova platform rm ios
> cordova platform remove ios
/usr/local/lib/node_modules/cordova/node_modules/conf/node_modules/write-file-atomic/index.js:236
throw err
^

Error: EACCES: permission denied, open '/Users/kalemmacbookpro/Library/Preferences/insight-nodejs/insight-cordova.json.1908726309'
at Object.openSync (fs.js:458:3)
at Function.writeFileSync [as sync] (/usr/local/lib/node_modules/cordova/node_modules/conf/node_modules/write-file-atomic/index.js:212:13)
at Conf.set store [as store] (/usr/local/lib/node_modules/cordova/node_modules/conf/index.js:142:19)
at new Conf (/usr/local/lib/node_modules/cordova/node_modules/conf/index.js:44:14)
at new Insight (/usr/local/lib/node_modules/cordova/node_modules/insight/lib/index.js:40:35)
at new RelentlessInsight (/usr/local/lib/node_modules/cordova/src/telemetry.js:31:1)
at Object.<anonymous> (/usr/local/lib/node_modules/cordova/src/telemetry.js:39:15)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/Users/kalemmacbookpro/Library/Preferences/insight-nodejs/insight-cordova.json.1908726309'
}
    [ERROR] An error occurred while running subprocess cordova.
    
    cordova platform remove ios exited with exit code 1.
    
    Re-running this command with the --verbose flag may provide more information.

But if I use this code with SUDO, everything is normal. How can I use all ionic code without SUDO?


Solution

  • EACCES permission errors can occur when packages are installed globally. If this is the case, npm may need to be set up to operate without elevated permissions. - Resolving Permission Errors

    The best way to avoid permission issues is to reinstall NodeJS and npm using a node version manager.

    See the nvm docs for full documentation.

    1.) Install nvm.

    $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    

    2.) New terminals will now use nvm. To verify, open a new terminal and run the following. If something prints, the installation was successful.

    $ command -v nvm
    

    3.) To download and install the latest LTS release of NodeJS, run:

    $ nvm install --lts
    

    4.) Set the newly installed NodeJS as the default environment:

    $ nvm alias default lts/*
    

    5.) New terminals will now use the nvm-controlled NodeJS. To verify:

    $ node -v  # will print the version installed above
    $ which npm  # will print a path somewhere within the ~/.nvm folder