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

后端 未结 22 1269
轮回少年
轮回少年 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条回答
  •  -上瘾入骨i
    2020-12-02 04:20

    To check if packagename was installed, type:

    dpkg -s 
    

    You can also use dpkg-query that has a neater output for your purpose, and accepts wild cards, too.

    dpkg-query -l 
    

    To find what package owns the command, try:

    dpkg -S `which `
    

    For further details, see article Find out if package is installed in Linux and dpkg cheat sheet.

提交回复
热议问题