Script to check if some program is already installed












6














How can I create a bash script that checks if a program is already installed, and if it isn't, installs it?



Thanks for your help.



Here's the code I have so far:



#/bin/bash

PS3="choose an option"

select opcion in "Installing_Youtube" "exit"

do

case $opcion in


"Installing_Youtube")

youtube-dl > /usr/bin
if [ $? -eq 127 ] ; then
echo "installing youtube"
apt-get update
apt-get install youtube-dl
mkdir Videos
else
echo "Youtube already installed"
fi

;;


"exit")
exit









share|improve this question









New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 9




    Do you intend to overwrite /usr/bin ?
    – D. Ben Knoble
    Dec 23 at 0:51






  • 1




    Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
    – Xen2050
    Dec 23 at 3:27










  • Why do you want to check it? What's the purposed use of this script?
    – Braiam
    2 days ago
















6














How can I create a bash script that checks if a program is already installed, and if it isn't, installs it?



Thanks for your help.



Here's the code I have so far:



#/bin/bash

PS3="choose an option"

select opcion in "Installing_Youtube" "exit"

do

case $opcion in


"Installing_Youtube")

youtube-dl > /usr/bin
if [ $? -eq 127 ] ; then
echo "installing youtube"
apt-get update
apt-get install youtube-dl
mkdir Videos
else
echo "Youtube already installed"
fi

;;


"exit")
exit









share|improve this question









New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 9




    Do you intend to overwrite /usr/bin ?
    – D. Ben Knoble
    Dec 23 at 0:51






  • 1




    Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
    – Xen2050
    Dec 23 at 3:27










  • Why do you want to check it? What's the purposed use of this script?
    – Braiam
    2 days ago














6












6








6







How can I create a bash script that checks if a program is already installed, and if it isn't, installs it?



Thanks for your help.



Here's the code I have so far:



#/bin/bash

PS3="choose an option"

select opcion in "Installing_Youtube" "exit"

do

case $opcion in


"Installing_Youtube")

youtube-dl > /usr/bin
if [ $? -eq 127 ] ; then
echo "installing youtube"
apt-get update
apt-get install youtube-dl
mkdir Videos
else
echo "Youtube already installed"
fi

;;


"exit")
exit









share|improve this question









New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











How can I create a bash script that checks if a program is already installed, and if it isn't, installs it?



Thanks for your help.



Here's the code I have so far:



#/bin/bash

PS3="choose an option"

select opcion in "Installing_Youtube" "exit"

do

case $opcion in


"Installing_Youtube")

youtube-dl > /usr/bin
if [ $? -eq 127 ] ; then
echo "installing youtube"
apt-get update
apt-get install youtube-dl
mkdir Videos
else
echo "Youtube already installed"
fi

;;


"exit")
exit






apt bash scripts






share|improve this question









New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Dec 22 at 22:01









Elder Geek

26.4k952124




26.4k952124






New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Dec 22 at 19:30









GUILLEM NAVALON BABIA

437




437




New contributor




GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






GUILLEM NAVALON BABIA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 9




    Do you intend to overwrite /usr/bin ?
    – D. Ben Knoble
    Dec 23 at 0:51






  • 1




    Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
    – Xen2050
    Dec 23 at 3:27










  • Why do you want to check it? What's the purposed use of this script?
    – Braiam
    2 days ago














  • 9




    Do you intend to overwrite /usr/bin ?
    – D. Ben Knoble
    Dec 23 at 0:51






  • 1




    Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
    – Xen2050
    Dec 23 at 3:27










  • Why do you want to check it? What's the purposed use of this script?
    – Braiam
    2 days ago








9




9




Do you intend to overwrite /usr/bin ?
– D. Ben Knoble
Dec 23 at 0:51




Do you intend to overwrite /usr/bin ?
– D. Ben Knoble
Dec 23 at 0:51




1




1




Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
– Xen2050
Dec 23 at 3:27




Are you differentiating between package names, and executable filenames? Or want to check both? Only George's answer currently checks for executables
– Xen2050
Dec 23 at 3:27












Why do you want to check it? What's the purposed use of this script?
– Braiam
2 days ago




Why do you want to check it? What's the purposed use of this script?
– Braiam
2 days ago










5 Answers
5






active

oldest

votes


















5














you can do this:



dpkg -s <packagename> &> /dev/null



then check exit status.only if the exit status of the above command was equal to 0 then the package installed.



so:



   #!/bin/bash

echo "enter your package name"
read name

dpkg -s $name &> /dev/null

if [ $? -ne 0 ]

then
echo "not installed"
sudo apt-get update
sudo apt-get install $name

else
echo "installed"
fi





share|improve this answer























  • Really thank's! It works :D
    – GUILLEM NAVALON BABIA
    Dec 22 at 21:13












  • Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
    – Zanna
    Dec 22 at 21:30






  • 3




    Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
    – Sergiy Kolodyazhnyy
    Dec 22 at 21:36






  • 2




    Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
    – D. Ben Knoble
    Dec 23 at 0:52










  • indeed, checking the exit status is exactly what if does...
    – Zanna
    2 days ago



















4














Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.



function getreq {
dpkg-query --show "$1"
if [ "$?" = "0" ];
then
echo "$1" found
else
echo "$1" not found. Please approve installation.
sudo apt-get install "$1"
if [ "$?" = "0" ];
then echo "$1" installed successfully.
fi
fi
}





share|improve this answer































    3














    This line of command will check using the which program and will return 0 if installed and 1 if not:



    which apache | grep -o apache > /dev/null &&  echo 0 || echo 1


    Of course you will use it in this manner in your script:



    which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"


    A simple usage would be:





    #!/usr/bin/env bash
    set -e

    function checker() {
    which "$1" | grep -o "$1" > /dev/null && return 0 || return 1
    }

    if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi


    Note several things:




    1. You will have to deal with dependenciy issues while installing

    2. To avoid interaaction with script during install see here for examples.

    3. You can catch the return values from that function an use it to decide whether to install or not.






    share|improve this answer























    • which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
      – D. Ben Knoble
      Dec 23 at 0:54










    • Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
      – George Udosen
      2 days ago



















    3














    Why do you want to check it in the first place? Unless you have a good reason for it, don't do it, just apt-get install package over. If it's already installed it will be updated if there is a newer version available, if it is installed and it is up to date, nothing will happen. In case you have some configuration that needs to be applied, there are other options, like building an configuration package which depends on the package or using configuration management software like ansible.






    share|improve this answer










    New contributor




    user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.


























      1














      One easy way to check for installed packages using apt-mark:



      apt-mark showinstall will list all packages marked install (already installed, or queued for installation). After that, it's a simple matter of grepping the package(s) you care about.



      Example: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"






      share|improve this answer























      • You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
        – Eric Mintz
        Dec 22 at 21:13












      • @EricMintz - thanks for the improvement! Edited.
        – user535733
        Dec 23 at 1:31











      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
      });


      }
      });






      GUILLEM NAVALON BABIA is a new contributor. Be nice, and check out our Code of Conduct.










      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1103860%2fscript-to-check-if-some-program-is-already-installed%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      you can do this:



      dpkg -s <packagename> &> /dev/null



      then check exit status.only if the exit status of the above command was equal to 0 then the package installed.



      so:



         #!/bin/bash

      echo "enter your package name"
      read name

      dpkg -s $name &> /dev/null

      if [ $? -ne 0 ]

      then
      echo "not installed"
      sudo apt-get update
      sudo apt-get install $name

      else
      echo "installed"
      fi





      share|improve this answer























      • Really thank's! It works :D
        – GUILLEM NAVALON BABIA
        Dec 22 at 21:13












      • Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
        – Zanna
        Dec 22 at 21:30






      • 3




        Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
        – Sergiy Kolodyazhnyy
        Dec 22 at 21:36






      • 2




        Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
        – D. Ben Knoble
        Dec 23 at 0:52










      • indeed, checking the exit status is exactly what if does...
        – Zanna
        2 days ago
















      5














      you can do this:



      dpkg -s <packagename> &> /dev/null



      then check exit status.only if the exit status of the above command was equal to 0 then the package installed.



      so:



         #!/bin/bash

      echo "enter your package name"
      read name

      dpkg -s $name &> /dev/null

      if [ $? -ne 0 ]

      then
      echo "not installed"
      sudo apt-get update
      sudo apt-get install $name

      else
      echo "installed"
      fi





      share|improve this answer























      • Really thank's! It works :D
        – GUILLEM NAVALON BABIA
        Dec 22 at 21:13












      • Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
        – Zanna
        Dec 22 at 21:30






      • 3




        Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
        – Sergiy Kolodyazhnyy
        Dec 22 at 21:36






      • 2




        Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
        – D. Ben Knoble
        Dec 23 at 0:52










      • indeed, checking the exit status is exactly what if does...
        – Zanna
        2 days ago














      5












      5








      5






      you can do this:



      dpkg -s <packagename> &> /dev/null



      then check exit status.only if the exit status of the above command was equal to 0 then the package installed.



      so:



         #!/bin/bash

      echo "enter your package name"
      read name

      dpkg -s $name &> /dev/null

      if [ $? -ne 0 ]

      then
      echo "not installed"
      sudo apt-get update
      sudo apt-get install $name

      else
      echo "installed"
      fi





      share|improve this answer














      you can do this:



      dpkg -s <packagename> &> /dev/null



      then check exit status.only if the exit status of the above command was equal to 0 then the package installed.



      so:



         #!/bin/bash

      echo "enter your package name"
      read name

      dpkg -s $name &> /dev/null

      if [ $? -ne 0 ]

      then
      echo "not installed"
      sudo apt-get update
      sudo apt-get install $name

      else
      echo "installed"
      fi






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 2 days ago









      GUILLEM NAVALON BABIA

      437




      437










      answered Dec 22 at 20:25









      Hossein

      914




      914












      • Really thank's! It works :D
        – GUILLEM NAVALON BABIA
        Dec 22 at 21:13












      • Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
        – Zanna
        Dec 22 at 21:30






      • 3




        Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
        – Sergiy Kolodyazhnyy
        Dec 22 at 21:36






      • 2




        Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
        – D. Ben Knoble
        Dec 23 at 0:52










      • indeed, checking the exit status is exactly what if does...
        – Zanna
        2 days ago


















      • Really thank's! It works :D
        – GUILLEM NAVALON BABIA
        Dec 22 at 21:13












      • Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
        – Zanna
        Dec 22 at 21:30






      • 3




        Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
        – Sergiy Kolodyazhnyy
        Dec 22 at 21:36






      • 2




        Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
        – D. Ben Knoble
        Dec 23 at 0:52










      • indeed, checking the exit status is exactly what if does...
        – Zanna
        2 days ago
















      Really thank's! It works :D
      – GUILLEM NAVALON BABIA
      Dec 22 at 21:13






      Really thank's! It works :D
      – GUILLEM NAVALON BABIA
      Dec 22 at 21:13














      Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
      – Zanna
      Dec 22 at 21:30




      Except it doesn't? What happened to the line with sudo apt install $name? The command needs to go on the next line... Otherwise, nice work...
      – Zanna
      Dec 22 at 21:30




      3




      3




      Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
      – Sergiy Kolodyazhnyy
      Dec 22 at 21:36




      Note that software could be installed in a variety of ways, and dpkg is only relevant for installed debian packages. In OP's particular case, youtube-dl for instance could be also installed via python's package manager pip
      – Sergiy Kolodyazhnyy
      Dec 22 at 21:36




      2




      2




      Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
      – D. Ben Knoble
      Dec 23 at 0:52




      Why not if dpkg -s “$name” &> /dev/null ; then ? Same effect, cleaner/clearer imo.
      – D. Ben Knoble
      Dec 23 at 0:52












      indeed, checking the exit status is exactly what if does...
      – Zanna
      2 days ago




      indeed, checking the exit status is exactly what if does...
      – Zanna
      2 days ago













      4














      Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.



      function getreq {
      dpkg-query --show "$1"
      if [ "$?" = "0" ];
      then
      echo "$1" found
      else
      echo "$1" not found. Please approve installation.
      sudo apt-get install "$1"
      if [ "$?" = "0" ];
      then echo "$1" installed successfully.
      fi
      fi
      }





      share|improve this answer




























        4














        Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.



        function getreq {
        dpkg-query --show "$1"
        if [ "$?" = "0" ];
        then
        echo "$1" found
        else
        echo "$1" not found. Please approve installation.
        sudo apt-get install "$1"
        if [ "$?" = "0" ];
        then echo "$1" installed successfully.
        fi
        fi
        }





        share|improve this answer


























          4












          4








          4






          Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.



          function getreq {
          dpkg-query --show "$1"
          if [ "$?" = "0" ];
          then
          echo "$1" found
          else
          echo "$1" not found. Please approve installation.
          sudo apt-get install "$1"
          if [ "$?" = "0" ];
          then echo "$1" installed successfully.
          fi
          fi
          }





          share|improve this answer














          Here's a function I wrote for the purpose that I use in my scripts. It checks to see if the required package is installed and if not, prompts the user to install it. It requires a package name as a parameter. If you don't know the name of the package a required program belongs to you can look it up. Information on that available here.



          function getreq {
          dpkg-query --show "$1"
          if [ "$?" = "0" ];
          then
          echo "$1" found
          else
          echo "$1" not found. Please approve installation.
          sudo apt-get install "$1"
          if [ "$?" = "0" ];
          then echo "$1" installed successfully.
          fi
          fi
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered Dec 22 at 21:31









          Elder Geek

          26.4k952124




          26.4k952124























              3














              This line of command will check using the which program and will return 0 if installed and 1 if not:



              which apache | grep -o apache > /dev/null &&  echo 0 || echo 1


              Of course you will use it in this manner in your script:



              which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"


              A simple usage would be:





              #!/usr/bin/env bash
              set -e

              function checker() {
              which "$1" | grep -o "$1" > /dev/null && return 0 || return 1
              }

              if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi


              Note several things:




              1. You will have to deal with dependenciy issues while installing

              2. To avoid interaaction with script during install see here for examples.

              3. You can catch the return values from that function an use it to decide whether to install or not.






              share|improve this answer























              • which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
                – D. Ben Knoble
                Dec 23 at 0:54










              • Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
                – George Udosen
                2 days ago
















              3














              This line of command will check using the which program and will return 0 if installed and 1 if not:



              which apache | grep -o apache > /dev/null &&  echo 0 || echo 1


              Of course you will use it in this manner in your script:



              which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"


              A simple usage would be:





              #!/usr/bin/env bash
              set -e

              function checker() {
              which "$1" | grep -o "$1" > /dev/null && return 0 || return 1
              }

              if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi


              Note several things:




              1. You will have to deal with dependenciy issues while installing

              2. To avoid interaaction with script during install see here for examples.

              3. You can catch the return values from that function an use it to decide whether to install or not.






              share|improve this answer























              • which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
                – D. Ben Knoble
                Dec 23 at 0:54










              • Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
                – George Udosen
                2 days ago














              3












              3








              3






              This line of command will check using the which program and will return 0 if installed and 1 if not:



              which apache | grep -o apache > /dev/null &&  echo 0 || echo 1


              Of course you will use it in this manner in your script:



              which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"


              A simple usage would be:





              #!/usr/bin/env bash
              set -e

              function checker() {
              which "$1" | grep -o "$1" > /dev/null && return 0 || return 1
              }

              if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi


              Note several things:




              1. You will have to deal with dependenciy issues while installing

              2. To avoid interaaction with script during install see here for examples.

              3. You can catch the return values from that function an use it to decide whether to install or not.






              share|improve this answer














              This line of command will check using the which program and will return 0 if installed and 1 if not:



              which apache | grep -o apache > /dev/null &&  echo 0 || echo 1


              Of course you will use it in this manner in your script:



              which "$1" | grep -o "$1" > /dev/null &&  echo "Installed!" || echo "Not Installed!"


              A simple usage would be:





              #!/usr/bin/env bash
              set -e

              function checker() {
              which "$1" | grep -o "$1" > /dev/null && return 0 || return 1
              }

              if checker "$1" == 0 ; then echo "Installed"; else echo "Not Installed!"; fi


              Note several things:




              1. You will have to deal with dependenciy issues while installing

              2. To avoid interaaction with script during install see here for examples.

              3. You can catch the return values from that function an use it to decide whether to install or not.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 22 at 20:49

























              answered Dec 22 at 20:27









              George Udosen

              19.4k94266




              19.4k94266












              • which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
                – D. Ben Knoble
                Dec 23 at 0:54










              • Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
                – George Udosen
                2 days ago


















              • which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
                – D. Ben Knoble
                Dec 23 at 0:54










              • Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
                – George Udosen
                2 days ago
















              which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
              – D. Ben Knoble
              Dec 23 at 0:54




              which is super non-portable. I frequently use command -v instead, but it depends heavily on the type of name you’re looking for (alias, function, executable, &c.)
              – D. Ben Knoble
              Dec 23 at 0:54












              Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
              – George Udosen
              2 days ago




              Super non-portable for a question that is for an Ubuntu machine? This is isn't Unix & Linux site! If i were answering it on Unix & Linux site that would be a different matter!
              – George Udosen
              2 days ago











              3














              Why do you want to check it in the first place? Unless you have a good reason for it, don't do it, just apt-get install package over. If it's already installed it will be updated if there is a newer version available, if it is installed and it is up to date, nothing will happen. In case you have some configuration that needs to be applied, there are other options, like building an configuration package which depends on the package or using configuration management software like ansible.






              share|improve this answer










              New contributor




              user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                3














                Why do you want to check it in the first place? Unless you have a good reason for it, don't do it, just apt-get install package over. If it's already installed it will be updated if there is a newer version available, if it is installed and it is up to date, nothing will happen. In case you have some configuration that needs to be applied, there are other options, like building an configuration package which depends on the package or using configuration management software like ansible.






                share|improve this answer










                New contributor




                user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  3












                  3








                  3






                  Why do you want to check it in the first place? Unless you have a good reason for it, don't do it, just apt-get install package over. If it's already installed it will be updated if there is a newer version available, if it is installed and it is up to date, nothing will happen. In case you have some configuration that needs to be applied, there are other options, like building an configuration package which depends on the package or using configuration management software like ansible.






                  share|improve this answer










                  New contributor




                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  Why do you want to check it in the first place? Unless you have a good reason for it, don't do it, just apt-get install package over. If it's already installed it will be updated if there is a newer version available, if it is installed and it is up to date, nothing will happen. In case you have some configuration that needs to be applied, there are other options, like building an configuration package which depends on the package or using configuration management software like ansible.







                  share|improve this answer










                  New contributor




                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer








                  edited 2 days ago









                  Zanna

                  50k13131238




                  50k13131238






                  New contributor




                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Dec 23 at 3:16









                  user2567875

                  1311




                  1311




                  New contributor




                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  user2567875 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.























                      1














                      One easy way to check for installed packages using apt-mark:



                      apt-mark showinstall will list all packages marked install (already installed, or queued for installation). After that, it's a simple matter of grepping the package(s) you care about.



                      Example: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"






                      share|improve this answer























                      • You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                        – Eric Mintz
                        Dec 22 at 21:13












                      • @EricMintz - thanks for the improvement! Edited.
                        – user535733
                        Dec 23 at 1:31
















                      1














                      One easy way to check for installed packages using apt-mark:



                      apt-mark showinstall will list all packages marked install (already installed, or queued for installation). After that, it's a simple matter of grepping the package(s) you care about.



                      Example: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"






                      share|improve this answer























                      • You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                        – Eric Mintz
                        Dec 22 at 21:13












                      • @EricMintz - thanks for the improvement! Edited.
                        – user535733
                        Dec 23 at 1:31














                      1












                      1








                      1






                      One easy way to check for installed packages using apt-mark:



                      apt-mark showinstall will list all packages marked install (already installed, or queued for installation). After that, it's a simple matter of grepping the package(s) you care about.



                      Example: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"






                      share|improve this answer














                      One easy way to check for installed packages using apt-mark:



                      apt-mark showinstall will list all packages marked install (already installed, or queued for installation). After that, it's a simple matter of grepping the package(s) you care about.



                      Example: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 23 at 1:30

























                      answered Dec 22 at 19:51









                      user535733

                      7,62722942




                      7,62722942












                      • You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                        – Eric Mintz
                        Dec 22 at 21:13












                      • @EricMintz - thanks for the improvement! Edited.
                        – user535733
                        Dec 23 at 1:31


















                      • You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                        – Eric Mintz
                        Dec 22 at 21:13












                      • @EricMintz - thanks for the improvement! Edited.
                        – user535733
                        Dec 23 at 1:31
















                      You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                      – Eric Mintz
                      Dec 22 at 21:13






                      You're on the right track! Just change it to this to eliminate the false positives: apt-mark showinstall | grep -q "^$PACKAGE_NAME$" && echo "installed" || echo "not"
                      – Eric Mintz
                      Dec 22 at 21:13














                      @EricMintz - thanks for the improvement! Edited.
                      – user535733
                      Dec 23 at 1:31




                      @EricMintz - thanks for the improvement! Edited.
                      – user535733
                      Dec 23 at 1:31










                      GUILLEM NAVALON BABIA is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      GUILLEM NAVALON BABIA is a new contributor. Be nice, and check out our Code of Conduct.













                      GUILLEM NAVALON BABIA is a new contributor. Be nice, and check out our Code of Conduct.












                      GUILLEM NAVALON BABIA is a new contributor. Be nice, and check out our Code of Conduct.
















                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f1103860%2fscript-to-check-if-some-program-is-already-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

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]