How to install .deb with dpkg non-interactively?

后端 未结 2 1966
小鲜肉
小鲜肉 2021-01-22 19:54

I\'m trying to install a .deb file... for example: example.deb. But the program is already installed in an older version on the Debian minimal server.

So doing dpk

相关标签:
2条回答
  • 2021-01-22 20:28

    You can pipe yes into it:

    yes | dpkg -i package.deb
    

    man yes

    0 讨论(0)
  • 2021-01-22 20:29

    You seem to be looking for

    dpkg --force-confold -i package.deb
    

    to specify that dpkg should prefer the existing, old configuration files in the case when there is a conflict.

    More broadly, the proper solution depends on how desperate you are to avoid interactive prompts, and which prompts precisely you want to avoid.

    dpkg has a number of options to select a particular behavior for various types of situations. Refer to its man page; scroll to the section on --force-things; one of them is --force-confold, or conversely --force-confnew to always replace any existing configuration file. (Many modern packages have a facility to upgrade any unchanged configurations completely automatically, but manually changed configuration files still require manual updating or merging.)

    If you aren't running dpkg directly, apt and friends allow you to pass options to it with

    apt install -o Dpkg::Options::="--force-confold" install package
    

    (Yeah, that's a lot of colons. You probably want install -y to avoid interactive prompting by Apt itself, too.)

    Setting the environment variable DEBIAN_FRONTEND to the string noninteractive will make Debconf (the configuration management component of Debian) select the default answer for all questions, and disable any prompting.

    If the default answers to a package's configuration questions are not suitable, you can preseed Debconf's configuration database with the settings you want. You'll need to install debconf-utils which contains the utility debconf-set-selections. See further its man page and e.g. some sections of https://wiki.debian.org/DebianInstaller/Preseed (though this is rather focused en preseeding the installer, so you can potentially perform an unattended installation of all of Debian).

    The problem with

    yes | dpkg -i package.deb
    

    is that you can't exactly predict which prompts are going to be shown, depending on the package's and the hosting system's configuration; you might say yes to something you didn't want to, or perhaps tell the system that your domain name or default database user is yes. Debconf was designed to give you very detailed and, for the most part, very safe and robust control over package installation - use that power.

    0 讨论(0)
提交回复
热议问题