Search code examples
javascriptlinuxelectronsudo

Install a dependency using Electron on Linux


I'm developing an Electron application, from which I need to install a dependency.
The package sudo-prompt ended up partly working.
My code:

const sudo = require("sudo-prompt");
sudo.exec("apt-get install lib32gcc1", {name: "SteamCMD GUI"}, (error, stdout, stderr) => {
   // The code here doesn't execute, as it possibly waits for the user's confirmation to press Y and Enter 
});

And the dependency never gets installed.

How to solve it?
Thanks!


Solution

  • Try it like this:

    const sudo = require("sudo-prompt");// The -y did the trick
    sudo.exec("apt-get install lib32gcc1 -y", {name: "SteamCMD GUI"}, (error, stdout, stderr) => {
       // The code here doesn't execute, as it possibly waits for the user's confirmation to press Y and Enter 
    });
    

    The -y option makes apt-get skip the prompts.