Skip already-installed packages in “yum install”?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












It seems that if a package is already installed, "yum install" will try to update it to the latest version. This will cause "yum install" to fail if the latest version is missing dependencies. I know that I can suppress this with --skip-broken, but I don't want to "skip broken" in case of packages which are not already installed; in that case I want it to fail.



I have seen in this answer that I can do this using an "if" statement if I am installing just one package, but I have a "yum install" statement containing some 15 packages, and don't want to run yum multiple times (once for each package) as this adds a lot of overhead.



How can I get yum to only install packages if they are not already present?







share|improve this question


























    up vote
    1
    down vote

    favorite












    It seems that if a package is already installed, "yum install" will try to update it to the latest version. This will cause "yum install" to fail if the latest version is missing dependencies. I know that I can suppress this with --skip-broken, but I don't want to "skip broken" in case of packages which are not already installed; in that case I want it to fail.



    I have seen in this answer that I can do this using an "if" statement if I am installing just one package, but I have a "yum install" statement containing some 15 packages, and don't want to run yum multiple times (once for each package) as this adds a lot of overhead.



    How can I get yum to only install packages if they are not already present?







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      It seems that if a package is already installed, "yum install" will try to update it to the latest version. This will cause "yum install" to fail if the latest version is missing dependencies. I know that I can suppress this with --skip-broken, but I don't want to "skip broken" in case of packages which are not already installed; in that case I want it to fail.



      I have seen in this answer that I can do this using an "if" statement if I am installing just one package, but I have a "yum install" statement containing some 15 packages, and don't want to run yum multiple times (once for each package) as this adds a lot of overhead.



      How can I get yum to only install packages if they are not already present?







      share|improve this question














      It seems that if a package is already installed, "yum install" will try to update it to the latest version. This will cause "yum install" to fail if the latest version is missing dependencies. I know that I can suppress this with --skip-broken, but I don't want to "skip broken" in case of packages which are not already installed; in that case I want it to fail.



      I have seen in this answer that I can do this using an "if" statement if I am installing just one package, but I have a "yum install" statement containing some 15 packages, and don't want to run yum multiple times (once for each package) as this adds a lot of overhead.



      How can I get yum to only install packages if they are not already present?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 30 '17 at 1:53

























      asked Nov 29 '17 at 11:18









      Kidburla

      5551212




      5551212




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          In the end I wrote a simple bash script yum-install-if-missing.sh based on other answers. Not sure if there is an easier way.



          #!/bin/bash

          yumcmd="yum install -y"
          for var in "$@"
          do
          if ! rpm --quiet --query $var; then
          yumcmd="$yumcmd $var"
          fi
          done

          echo "ABOUT TO EXECUTE: $yumcmd"

          eval $yumcmd


          It can then be executed as: yum-install-if-missing.sh packageone packagetwo and so on.






          share|improve this answer


















          • 2




            Use rpm -q --quiet packagename rather than piping to grep.
            – Wildcard
            Nov 30 '17 at 2:02










          • @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
            – Kidburla
            Dec 6 '17 at 16:59











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407713%2fskip-already-installed-packages-in-yum-install%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          In the end I wrote a simple bash script yum-install-if-missing.sh based on other answers. Not sure if there is an easier way.



          #!/bin/bash

          yumcmd="yum install -y"
          for var in "$@"
          do
          if ! rpm --quiet --query $var; then
          yumcmd="$yumcmd $var"
          fi
          done

          echo "ABOUT TO EXECUTE: $yumcmd"

          eval $yumcmd


          It can then be executed as: yum-install-if-missing.sh packageone packagetwo and so on.






          share|improve this answer


















          • 2




            Use rpm -q --quiet packagename rather than piping to grep.
            – Wildcard
            Nov 30 '17 at 2:02










          • @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
            – Kidburla
            Dec 6 '17 at 16:59















          up vote
          2
          down vote













          In the end I wrote a simple bash script yum-install-if-missing.sh based on other answers. Not sure if there is an easier way.



          #!/bin/bash

          yumcmd="yum install -y"
          for var in "$@"
          do
          if ! rpm --quiet --query $var; then
          yumcmd="$yumcmd $var"
          fi
          done

          echo "ABOUT TO EXECUTE: $yumcmd"

          eval $yumcmd


          It can then be executed as: yum-install-if-missing.sh packageone packagetwo and so on.






          share|improve this answer


















          • 2




            Use rpm -q --quiet packagename rather than piping to grep.
            – Wildcard
            Nov 30 '17 at 2:02










          • @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
            – Kidburla
            Dec 6 '17 at 16:59













          up vote
          2
          down vote










          up vote
          2
          down vote









          In the end I wrote a simple bash script yum-install-if-missing.sh based on other answers. Not sure if there is an easier way.



          #!/bin/bash

          yumcmd="yum install -y"
          for var in "$@"
          do
          if ! rpm --quiet --query $var; then
          yumcmd="$yumcmd $var"
          fi
          done

          echo "ABOUT TO EXECUTE: $yumcmd"

          eval $yumcmd


          It can then be executed as: yum-install-if-missing.sh packageone packagetwo and so on.






          share|improve this answer














          In the end I wrote a simple bash script yum-install-if-missing.sh based on other answers. Not sure if there is an easier way.



          #!/bin/bash

          yumcmd="yum install -y"
          for var in "$@"
          do
          if ! rpm --quiet --query $var; then
          yumcmd="$yumcmd $var"
          fi
          done

          echo "ABOUT TO EXECUTE: $yumcmd"

          eval $yumcmd


          It can then be executed as: yum-install-if-missing.sh packageone packagetwo and so on.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 6 '17 at 16:58

























          answered Nov 29 '17 at 13:51









          Kidburla

          5551212




          5551212







          • 2




            Use rpm -q --quiet packagename rather than piping to grep.
            – Wildcard
            Nov 30 '17 at 2:02










          • @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
            – Kidburla
            Dec 6 '17 at 16:59













          • 2




            Use rpm -q --quiet packagename rather than piping to grep.
            – Wildcard
            Nov 30 '17 at 2:02










          • @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
            – Kidburla
            Dec 6 '17 at 16:59








          2




          2




          Use rpm -q --quiet packagename rather than piping to grep.
          – Wildcard
          Nov 30 '17 at 2:02




          Use rpm -q --quiet packagename rather than piping to grep.
          – Wildcard
          Nov 30 '17 at 2:02












          @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
          – Kidburla
          Dec 6 '17 at 16:59





          @Wildcard thanks! this really helped me. because I was running yum-install-if-missing.sh ... file ... and while file was not installed, file-libs was installed, so file got skipped. your suggestion fixed this problem
          – Kidburla
          Dec 6 '17 at 16:59


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407713%2fskip-already-installed-packages-in-yum-install%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay