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

后端 未结 22 1311
轮回少年
轮回少年 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条回答
  •  一向
    一向 (楼主)
    2020-12-02 04:28

    It seems that nowadays apt-get has an option --no-upgrade that just does what the OP wants:

    --no-upgrade Do not upgrade packages. When used in conjunction with install, no-upgrade will prevent packages listed from being upgraded if they are already installed.

    Manpage from https://linux.die.net/man/8/apt-get

    Therefore you can use

    apt-get install --no-upgrade package
    

    and package will be installed only if it's not.

提交回复
热议问题