How to check if a virtual package is installed?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















In the following question there is a solution to checking for a package prior to installing it:



How do I check if a package is installed on my server?



However, I have found that this does not work for Virtual Packages.



Is there a way to traverse the package name that apt-get automatically select and check for the correct one?










share|improve this question































    5















    In the following question there is a solution to checking for a package prior to installing it:



    How do I check if a package is installed on my server?



    However, I have found that this does not work for Virtual Packages.



    Is there a way to traverse the package name that apt-get automatically select and check for the correct one?










    share|improve this question



























      5












      5








      5


      1






      In the following question there is a solution to checking for a package prior to installing it:



      How do I check if a package is installed on my server?



      However, I have found that this does not work for Virtual Packages.



      Is there a way to traverse the package name that apt-get automatically select and check for the correct one?










      share|improve this question
















      In the following question there is a solution to checking for a package prior to installing it:



      How do I check if a package is installed on my server?



      However, I have found that this does not work for Virtual Packages.



      Is there a way to traverse the package name that apt-get automatically select and check for the correct one?







      apt package-management dpkg






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 22 '17 at 15:29







      Noki

















      asked Sep 27 '15 at 23:46









      NokiNoki

      42211025




      42211025






















          4 Answers
          4






          active

          oldest

          votes


















          4














          You can use grep-status (package dctrl-tools, not installed by default) to find all installed packages providing some virtual package:



          $ grep-status -FProvides,Package -sPackage,Provides,Status awk 
          Package: mawk
          Provides: awk
          Status: install ok installed

          Package: gawk
          Provides: awk
          Status: install ok installed





          share|improve this answer
























          • This sounds perfect, I will try it when I'm free and respond back. Thanks!

            – Noki
            Sep 30 '15 at 11:24



















          6














          Apt will not install a virtual package unless there is only one provider for it. If another package depends on a virtual package, it usually also names a real package as an alternative (i.e. build-essential depend on "libc6-dev | libc-dev" - the second being a virtual package).



          Virtual packages are not installed, thus you cannot check their status. You can use apt-cache showpkg <pkg-name> to view which packages provide the virtual package, and then check whether any of these are installed.






          share|improve this answer

































            1














            @FlorianDiesch'answer looks interesting, but I want something without need for any software not installed by default.



            I ended up using this:



            function check_packages_and_install_if_absent()
            {
            for PACKAGENAME
            do
            if
            dpkg -l "$PACKAGENAME" | grep ^ii
            then
            echo "Package $PACKAGENAME is present"
            continue
            fi

            FOUND=""

            while read ACTUALPACKAGENAME
            do
            echo "$PACKAGENAME is a virtual package, that can be provided by $ACTUALPACKAGENAME"

            if
            dpkg -l "$ACTUALPACKAGENAME" | grep ^ii
            then
            echo "Actual package $ACTUALPACKAGENAME is present"
            FOUND=true
            break;
            fi

            done < <( apt-cache showpkg "${PACKAGENAME}" | sed -e '1,/^Reverse Provides: *$/ d' -e 's/ .*$//' | sort | uniq )

            # Using sed to print lines after match
            # https://stackoverflow.com/questions/32569032/sed-print-all-lines-after-match#answer-32569573

            if [[ "$FOUND" == "true" ]]
            then
            continue
            fi

            echo "Package $PACKAGENAME is absent, installing"
            sudo apt-get install -y "$PACKAGENAME"
            done
            }


            You can call it with a list of normal and/or virtual package names:



            function check_packages_and_install_if_absent foo bar baz





            share|improve this answer

































              -3














              You can query the database of installed packages for packagename with



              dpkg -l packagename   


              And you can list all the files in packagename with



              dpkg -L packagename


              Read man dpkg for more information, like how to use wildcards.






              share|improve this answer
























              • As stated in the question this does not work for virtual packages.

                – Florian Diesch
                Sep 28 '15 at 2:43












              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f679137%2fhow-to-check-if-a-virtual-package-is-installed%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              4














              You can use grep-status (package dctrl-tools, not installed by default) to find all installed packages providing some virtual package:



              $ grep-status -FProvides,Package -sPackage,Provides,Status awk 
              Package: mawk
              Provides: awk
              Status: install ok installed

              Package: gawk
              Provides: awk
              Status: install ok installed





              share|improve this answer
























              • This sounds perfect, I will try it when I'm free and respond back. Thanks!

                – Noki
                Sep 30 '15 at 11:24
















              4














              You can use grep-status (package dctrl-tools, not installed by default) to find all installed packages providing some virtual package:



              $ grep-status -FProvides,Package -sPackage,Provides,Status awk 
              Package: mawk
              Provides: awk
              Status: install ok installed

              Package: gawk
              Provides: awk
              Status: install ok installed





              share|improve this answer
























              • This sounds perfect, I will try it when I'm free and respond back. Thanks!

                – Noki
                Sep 30 '15 at 11:24














              4












              4








              4







              You can use grep-status (package dctrl-tools, not installed by default) to find all installed packages providing some virtual package:



              $ grep-status -FProvides,Package -sPackage,Provides,Status awk 
              Package: mawk
              Provides: awk
              Status: install ok installed

              Package: gawk
              Provides: awk
              Status: install ok installed





              share|improve this answer













              You can use grep-status (package dctrl-tools, not installed by default) to find all installed packages providing some virtual package:



              $ grep-status -FProvides,Package -sPackage,Provides,Status awk 
              Package: mawk
              Provides: awk
              Status: install ok installed

              Package: gawk
              Provides: awk
              Status: install ok installed






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Sep 28 '15 at 2:56









              Florian DieschFlorian Diesch

              66.1k16168183




              66.1k16168183













              • This sounds perfect, I will try it when I'm free and respond back. Thanks!

                – Noki
                Sep 30 '15 at 11:24



















              • This sounds perfect, I will try it when I'm free and respond back. Thanks!

                – Noki
                Sep 30 '15 at 11:24

















              This sounds perfect, I will try it when I'm free and respond back. Thanks!

              – Noki
              Sep 30 '15 at 11:24





              This sounds perfect, I will try it when I'm free and respond back. Thanks!

              – Noki
              Sep 30 '15 at 11:24













              6














              Apt will not install a virtual package unless there is only one provider for it. If another package depends on a virtual package, it usually also names a real package as an alternative (i.e. build-essential depend on "libc6-dev | libc-dev" - the second being a virtual package).



              Virtual packages are not installed, thus you cannot check their status. You can use apt-cache showpkg <pkg-name> to view which packages provide the virtual package, and then check whether any of these are installed.






              share|improve this answer






























                6














                Apt will not install a virtual package unless there is only one provider for it. If another package depends on a virtual package, it usually also names a real package as an alternative (i.e. build-essential depend on "libc6-dev | libc-dev" - the second being a virtual package).



                Virtual packages are not installed, thus you cannot check their status. You can use apt-cache showpkg <pkg-name> to view which packages provide the virtual package, and then check whether any of these are installed.






                share|improve this answer




























                  6












                  6








                  6







                  Apt will not install a virtual package unless there is only one provider for it. If another package depends on a virtual package, it usually also names a real package as an alternative (i.e. build-essential depend on "libc6-dev | libc-dev" - the second being a virtual package).



                  Virtual packages are not installed, thus you cannot check their status. You can use apt-cache showpkg <pkg-name> to view which packages provide the virtual package, and then check whether any of these are installed.






                  share|improve this answer















                  Apt will not install a virtual package unless there is only one provider for it. If another package depends on a virtual package, it usually also names a real package as an alternative (i.e. build-essential depend on "libc6-dev | libc-dev" - the second being a virtual package).



                  Virtual packages are not installed, thus you cannot check their status. You can use apt-cache showpkg <pkg-name> to view which packages provide the virtual package, and then check whether any of these are installed.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 28 '15 at 1:29

























                  answered Sep 28 '15 at 0:37







                  user448115






























                      1














                      @FlorianDiesch'answer looks interesting, but I want something without need for any software not installed by default.



                      I ended up using this:



                      function check_packages_and_install_if_absent()
                      {
                      for PACKAGENAME
                      do
                      if
                      dpkg -l "$PACKAGENAME" | grep ^ii
                      then
                      echo "Package $PACKAGENAME is present"
                      continue
                      fi

                      FOUND=""

                      while read ACTUALPACKAGENAME
                      do
                      echo "$PACKAGENAME is a virtual package, that can be provided by $ACTUALPACKAGENAME"

                      if
                      dpkg -l "$ACTUALPACKAGENAME" | grep ^ii
                      then
                      echo "Actual package $ACTUALPACKAGENAME is present"
                      FOUND=true
                      break;
                      fi

                      done < <( apt-cache showpkg "${PACKAGENAME}" | sed -e '1,/^Reverse Provides: *$/ d' -e 's/ .*$//' | sort | uniq )

                      # Using sed to print lines after match
                      # https://stackoverflow.com/questions/32569032/sed-print-all-lines-after-match#answer-32569573

                      if [[ "$FOUND" == "true" ]]
                      then
                      continue
                      fi

                      echo "Package $PACKAGENAME is absent, installing"
                      sudo apt-get install -y "$PACKAGENAME"
                      done
                      }


                      You can call it with a list of normal and/or virtual package names:



                      function check_packages_and_install_if_absent foo bar baz





                      share|improve this answer






























                        1














                        @FlorianDiesch'answer looks interesting, but I want something without need for any software not installed by default.



                        I ended up using this:



                        function check_packages_and_install_if_absent()
                        {
                        for PACKAGENAME
                        do
                        if
                        dpkg -l "$PACKAGENAME" | grep ^ii
                        then
                        echo "Package $PACKAGENAME is present"
                        continue
                        fi

                        FOUND=""

                        while read ACTUALPACKAGENAME
                        do
                        echo "$PACKAGENAME is a virtual package, that can be provided by $ACTUALPACKAGENAME"

                        if
                        dpkg -l "$ACTUALPACKAGENAME" | grep ^ii
                        then
                        echo "Actual package $ACTUALPACKAGENAME is present"
                        FOUND=true
                        break;
                        fi

                        done < <( apt-cache showpkg "${PACKAGENAME}" | sed -e '1,/^Reverse Provides: *$/ d' -e 's/ .*$//' | sort | uniq )

                        # Using sed to print lines after match
                        # https://stackoverflow.com/questions/32569032/sed-print-all-lines-after-match#answer-32569573

                        if [[ "$FOUND" == "true" ]]
                        then
                        continue
                        fi

                        echo "Package $PACKAGENAME is absent, installing"
                        sudo apt-get install -y "$PACKAGENAME"
                        done
                        }


                        You can call it with a list of normal and/or virtual package names:



                        function check_packages_and_install_if_absent foo bar baz





                        share|improve this answer




























                          1












                          1








                          1







                          @FlorianDiesch'answer looks interesting, but I want something without need for any software not installed by default.



                          I ended up using this:



                          function check_packages_and_install_if_absent()
                          {
                          for PACKAGENAME
                          do
                          if
                          dpkg -l "$PACKAGENAME" | grep ^ii
                          then
                          echo "Package $PACKAGENAME is present"
                          continue
                          fi

                          FOUND=""

                          while read ACTUALPACKAGENAME
                          do
                          echo "$PACKAGENAME is a virtual package, that can be provided by $ACTUALPACKAGENAME"

                          if
                          dpkg -l "$ACTUALPACKAGENAME" | grep ^ii
                          then
                          echo "Actual package $ACTUALPACKAGENAME is present"
                          FOUND=true
                          break;
                          fi

                          done < <( apt-cache showpkg "${PACKAGENAME}" | sed -e '1,/^Reverse Provides: *$/ d' -e 's/ .*$//' | sort | uniq )

                          # Using sed to print lines after match
                          # https://stackoverflow.com/questions/32569032/sed-print-all-lines-after-match#answer-32569573

                          if [[ "$FOUND" == "true" ]]
                          then
                          continue
                          fi

                          echo "Package $PACKAGENAME is absent, installing"
                          sudo apt-get install -y "$PACKAGENAME"
                          done
                          }


                          You can call it with a list of normal and/or virtual package names:



                          function check_packages_and_install_if_absent foo bar baz





                          share|improve this answer















                          @FlorianDiesch'answer looks interesting, but I want something without need for any software not installed by default.



                          I ended up using this:



                          function check_packages_and_install_if_absent()
                          {
                          for PACKAGENAME
                          do
                          if
                          dpkg -l "$PACKAGENAME" | grep ^ii
                          then
                          echo "Package $PACKAGENAME is present"
                          continue
                          fi

                          FOUND=""

                          while read ACTUALPACKAGENAME
                          do
                          echo "$PACKAGENAME is a virtual package, that can be provided by $ACTUALPACKAGENAME"

                          if
                          dpkg -l "$ACTUALPACKAGENAME" | grep ^ii
                          then
                          echo "Actual package $ACTUALPACKAGENAME is present"
                          FOUND=true
                          break;
                          fi

                          done < <( apt-cache showpkg "${PACKAGENAME}" | sed -e '1,/^Reverse Provides: *$/ d' -e 's/ .*$//' | sort | uniq )

                          # Using sed to print lines after match
                          # https://stackoverflow.com/questions/32569032/sed-print-all-lines-after-match#answer-32569573

                          if [[ "$FOUND" == "true" ]]
                          then
                          continue
                          fi

                          echo "Package $PACKAGENAME is absent, installing"
                          sudo apt-get install -y "$PACKAGENAME"
                          done
                          }


                          You can call it with a list of normal and/or virtual package names:



                          function check_packages_and_install_if_absent foo bar baz






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 29 at 16:48

























                          answered Mar 29 at 13:09









                          Stéphane GourichonStéphane Gourichon

                          1,3571527




                          1,3571527























                              -3














                              You can query the database of installed packages for packagename with



                              dpkg -l packagename   


                              And you can list all the files in packagename with



                              dpkg -L packagename


                              Read man dpkg for more information, like how to use wildcards.






                              share|improve this answer
























                              • As stated in the question this does not work for virtual packages.

                                – Florian Diesch
                                Sep 28 '15 at 2:43
















                              -3














                              You can query the database of installed packages for packagename with



                              dpkg -l packagename   


                              And you can list all the files in packagename with



                              dpkg -L packagename


                              Read man dpkg for more information, like how to use wildcards.






                              share|improve this answer
























                              • As stated in the question this does not work for virtual packages.

                                – Florian Diesch
                                Sep 28 '15 at 2:43














                              -3












                              -3








                              -3







                              You can query the database of installed packages for packagename with



                              dpkg -l packagename   


                              And you can list all the files in packagename with



                              dpkg -L packagename


                              Read man dpkg for more information, like how to use wildcards.






                              share|improve this answer













                              You can query the database of installed packages for packagename with



                              dpkg -l packagename   


                              And you can list all the files in packagename with



                              dpkg -L packagename


                              Read man dpkg for more information, like how to use wildcards.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Sep 28 '15 at 0:42









                              waltinatorwaltinator

                              23k74269




                              23k74269













                              • As stated in the question this does not work for virtual packages.

                                – Florian Diesch
                                Sep 28 '15 at 2:43



















                              • As stated in the question this does not work for virtual packages.

                                – Florian Diesch
                                Sep 28 '15 at 2:43

















                              As stated in the question this does not work for virtual packages.

                              – Florian Diesch
                              Sep 28 '15 at 2:43





                              As stated in the question this does not work for virtual packages.

                              – Florian Diesch
                              Sep 28 '15 at 2:43


















                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f679137%2fhow-to-check-if-a-virtual-package-is-installed%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              數位音樂下載

                              格利澤436b

                              When can things happen in Etherscan, such as the picture below?