Check if an apt-get package is installed and then install it if it's not on Linux

后端 未结 22 1312
轮回少年
轮回少年 2020-12-02 04:02

I\'m working on a Ubuntu system and currently this is what I\'m doing:

if ! which command > /dev/null; then
   echo -e \"Command not found! Install? (y/n)         


        
22条回答
  •  Happy的楠姐
    2020-12-02 04:09

    I offer this update since Ubuntu added its "Personal Package Archive" (PPA) just as this question was answered, and PPA packages have a different result.

    1. Native Debian repository package not installed:

      ~$ dpkg-query -l apache-perl
      ~$ echo $?
      1
      
    2. PPA package registered on host and installed:

      ~$ dpkg-query -l libreoffice
      ~$ echo $?
      0
      
    3. PPA package registered on host but not installed:

      ~$ dpkg-query -l domy-ce
      ~$ echo $?
      0
      ~$ sudo apt-get remove domy-ce
      [sudo] password for user: 
      Reading package lists... Done
      Building dependency tree       
      Reading state information... Done
      Package domy-ce is not installed, so not removed
      0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
      

    Also posted on: https://superuser.com/questions/427318/test-if-a-package-is-installed-in-apt/427898

提交回复
热议问题