Ubuntu通过apt-get安装指定版本和查询指定软件有多少个版本

一、通过apt-get安装指定版本

apt-get install <<package name>>=<<version>>

二、查询指定软件有多少个版本

说明:在Linux用这个查询并不能完全的把所有版本都列举出来,因为每个版本都与系统版本和CPU架构有关,比如一个软件支持Ubuntu系统的16.04的CPU架构为amd64的版本只有1.0和1.2,其余都不支持,所以列举时就只有两款。

列举版本列表:

0、通过网站搜索:

https://packages.ubuntu.com/

1、

apt-cache madison <<package name>>

将列出所有来源的版本。如下输出所示:

apt-cache madison vim
   vim | 2:7.3.547-1 | http://debian.mirrors.tds.net/debian/ unstable/main amd64 Packages
   vim | 2:7.3.429-2 | http://debian.mirrors.tds.net/debian/ testing/main amd64 Packages
   vim | 2:7.3.429-2 | http://http.us.debian.org/debian/ testing/main amd64 Packages
   vim | 2:7.3.429-2 | http://debian.mirrors.tds.net/debian/ testing/main Sources
   vim | 2:7.3.547-1 | http://debian.mirrors.tds.net/debian/ unstable/main Sources

madison是一个apt-cache子命令,可以通过man apt-cache查询更多用法。

2、

apt-cache policy <<package name>>

将列出所有来源的版本。信息会比上面详细一点,如下输出所示:

apt-cache policy gdb
gdb:
  Installed: 7.7.1-0ubuntu5~14.04.2
  Candidate: 7.7.1-0ubuntu5~14.04.2
  Version table:
 *** 7.7.1-0ubuntu5~14.04.2 0
        500 http://fr.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     7.7-0ubuntu3 0
        500 http://fr.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

policy是一个apt-cache子命令,可以通过man apt-cache查询更多用法。

3、

apt-cache showpkg <<package name>>

4、

apt-get install -s <<package-name>>

说明:这个命令只是模拟安装时会安装哪些软件列表,但不会例举出每个软件有多少个版本

5、

aptitude versions <<package name>>

参考:https://manpages.debian.org/unstable/aptitude/aptitude.8.en.html

6、

apt-show-versions -a <<package name>>

说明:列举出所有版本,且能查看是否已经安装。还可以通过apt-show-versions -u <<package name>>来查询是否有升级版本。

参考:http://manpages.ubuntu.com/manpages/trusty/man1/apt-show-versions.1p.html

7、

whohas -d Debian,Ubuntu <<package name>> | tr -s ' ' '\t' | cut -f 1-3 | column -t

8、

rmadison -u debian,ubuntu,bpo <<package name>> | cut -d "|" -f 1-3

单个详情:

1、

apt-cache show <<package name>>

说明:查询指定包的详情,不管是否已经安装。

2、

dpkg -l <<package name>>

说明:效果和上面基本一致,但是结果是列表详情展示,会提示是否已经删除了之后还有依赖包没有删除等。

3、

dpkg -s <<package name>>

说明:必须是安装的包才能显示详情。

4、

dpkg-query -s <<package name>>

说明:同上,效果一致。

使用技巧:

1、可以在查询后面带上一些参数来实现筛选

apt-cache show package | grep Version
apt-show-versions | more

 

参考:

http://wiki.ubuntu.org.cn/Apt%E5%92%8Cdpkg%E5%BF%AB%E9%80%9F%E5%8F%82%E8%80%83(apt-get常用语法)

https://superuser.com/questions/393681/how-to-find-out-which-versions-of-a-package-can-i-install-on-apt

https://stackoverflow.com/questions/18885820/how-to-check-the-version-before-install-packages-using-apt-get

https://askubuntu.com/questions/340530/how-can-i-check-the-available-version-of-a-package-in-the-repositories

https://serverfault.com/questions/108080/ubuntu-debian-show-list-of-available-versions-of-a-specific-package

https://askubuntu.com/questions/473886/list-all-versions-of-a-package

https://askubuntu.com/questions/447/how-can-i-see-all-versions-of-a-package-that-are-available-in-the-archive

http://www.wkii.org/view-package-version-ubuntu.html

posted @ 2017-07-10 03:40  EasonJim  阅读(143561)  评论(0编辑  收藏  举报