如何检查软件包是否已安装,如果没有安装,该如何安装?

编程入门 行业动态 更新时间:2024-10-26 00:25:15
本文介绍了如何检查软件包是否已安装,如果没有安装,该如何安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

有关更多详细信息,请参见文章 了解软件包是否已安装在Linux中 和 dpkg速查表.

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

更多推荐

如何检查软件包是否已安装,如果没有安装,该如何安装?

本文发布于:2023-07-17 06:38:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:软件包   如果没有   该如何

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!