如何检查软件包是否已安装,如果没有安装,该如何安装? [英] How to check if package installed and install it if not?

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

问题描述

我正在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?

推荐答案

要检查是否已安装 packagename ,请输入:

To check if packagename was installed, type:

dpkg -s <packagename>

您还可以使用 dpkg-query ,该输出具有更整洁的输出,并且可以接受通配符.

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

dpkg-query -l <packagename>

要查找什么包拥有 command ,请尝试:

To find what package owns the command, try:

dpkg -S `which <command>`

有关更多详细信息,请参见文章 dpkg速查表.

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

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

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