检查是否安装了软件包,然后安装它,如果它不是 [英] Check if a package is installed and then install it if it's not

查看:120
本文介绍了检查是否安装了软件包,然后安装它,如果它不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个Ubuntu系统上以及

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) \c"
   read
   if "$REPLY" = "y"; then
      sudo apt-get install command
   fi
fi

这是大多数人会做什么?还是有更好的解决方案?

Is this what most people would do? Or is there a more elegant solution?

推荐答案

要检查是否软件包名安装,键入:

To check if packagename was installed, type:

dpkg -s <packagename>

您也可以使用 dpkg的查询有供您使用更简洁的输出,并接受通配符了。

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

dpkg-query -l <packagename>

要找出什么包拥有命令,请尝试:

To find what package owns the command, try:

dpkg -S `which <command>`

有关进一步详情,请参阅文章的 找出是否软件包安装在Linux中 的和 dpkg的小抄

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

这篇关于检查是否安装了软件包,然后安装它,如果它不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆