Linux中apt-get和apt-cache命令使用详解

   2015-06-26 0
核心提示:这篇文章主要介绍了Linux中apt-get和apt-cache命令使用详解,作为包管理中最常用的命令,需要的朋友可以参考下

apt-get和apt-cache是Ubuntu Linux中的命令行下的包管理工具。 apt-get的GUI版本是Synaptic包管理器。本篇中我们会展示apt-get和apt-cache命令的15个不同例子。
示例:1 列出所有可用包

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-cache pkgnames
account-plugin-yahoojp
ceph-fuse
dvd+rw-tools
e3
gnome-commander-data
grub-gfxpayload-lists
gweled
.......................................

示例:2 用关键字搜索包

这个命令在你不确定包名时很有用,只要在apt-cache(LCTT 译注:这里原文是apt-get,应为笔误)后面输入与包相关的关键字即可。

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-cache search "web server"
apache2 - Apache HTTP Server
apache2-bin - Apache HTTP Server (binary files and modules)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)
apache2-doc - Apache HTTP Server (on-site documentation)
apache2-utils - Apache HTTP Server (utility programs for web servers)
......................................................................

注意: 如果你安装了“apt-file”包,我们就可以像下面那样用配置文件搜索包。

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-file search nagios.cfg
ganglia-nagios-bridge: /usr/share/doc/ganglia-nagios-bridge/nagios.cfg
nagios3-common: /etc/nagios3/nagios.cfg
nagios3-common: /usr/share/doc/nagios3-common/examples/nagios.cfg.gz
pnp4nagios-bin: /etc/pnp4nagios/nagios.cfg
pnp4nagios-bin: /usr/share/doc/pnp4nagios/examples/nagios.cfg

示例:3 显示特定包的基本信息

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-cache show postfix
Package: postfix
Priority: optional
Section: mail
Installed-Size: 3524
Maintainer: LaMont Jones <[emailprotected]<script cf-hash='f9e31' type="text/javascript"> /* Script"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */script>>
Architecture: amd64
Version: 2.11.1-1
Replaces: mail-transport-agent
Provides: default-mta, mail-transport-agent
.....................................................

示例:4 列出包的依赖

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-cache depends postfix
postfix
Depends: libc6
Depends: libdb5.3
Depends: libsasl2-2
Depends: libsqlite3-0
Depends: libssl1.0.0
|Depends: debconf
Depends: <debconf-2.0>
cdebconf
debconf
Depends: netbase
Depends: adduser
Depends: dpkg
............................................

示例:5 使用apt-cache显示缓存统计

   

复制代码
代码如下:
linuxtechi@localhost:~$ apt-cache stats
Total package names: 60877 (1,218 k)
Total package structures: 102824 (5,758 k)
Normal packages: 71285
Pure virtual packages: 1102
Single virtual packages: 9151
Mixed virtual packages: 1827
Missing: 19459
Total distinct versions: 74913 (5,394 k)
Total distinct descriptions: 93792 (2,251 k)
Total dependencies: 573443 (16.1 M)
Total ver/file relations: 78007 (1,872 k)
Total Desc/File relations: 93792 (2,251 k)
Total Provides mappings: 16583 (332 k)
Total globbed strings: 171 (2,263 )
Total dependency version space: 2,665 k
Total slack space: 37.3 k
Total space accounted for: 29.5 M

示例:6 使用 “apt-get update” 更新仓库

使用命令“apt-get update”, 我们可以重新从源仓库中同步文件索引。包的索引从“/etc/apt/sources.list”中检索。

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get update
Ign http://extras.ubuntu.com utopic InRelease
Hit http://extras.ubuntu.com utopic Release.gpg
Hit http://extras.ubuntu.com utopic Release
Hit http://extras.ubuntu.com utopic/main Sources
Hit http://extras.ubuntu.com utopic/main amd64 Packages
Hit http://extras.ubuntu.com utopic/main i386 Packages
Ign http://in.archive.ubuntu.com utopic InRelease
Ign http://in.archive.ubuntu.com utopic-updates InRelease
Ign http://in.archive.ubuntu.com utopic-backports InRelease
................................................................

示例:7 使用apt-get安装包

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get install icinga

上面的命令会安装叫“icinga”的包。
示例:8 升级所有已安装的包

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get upgrade

示例:9 更新特定的包

在apt-get命令中的“install”选项后面接上“-only-upgrade”用来更新一个特定的包,如下所示:

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get install filezilla --only-upgrade

示例:10 使用apt-get卸载包

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get remove skype

上面的命令只会删除skype包,如果你想要删除它的配置文件,在apt-get命令中使用“purge”选项。如下所示:

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get purge skype

我们可以结合使用上面的两个命令:

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get remove --purge skype

示例:11 在当前的目录中下载包

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get download icinga
Get:1 http://in.archive.ubuntu.com/ubuntu/ utopic/universe icinga amd64 1.11.6-1build1 [1,474 B]
Fetched 1,474 B in 1s (1,363 B/s)

上面的目录会把icinga包下载到你的当前工作目录。
示例:12 清理本地包占用的磁盘空间

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get clean

上面的命令会清空apt-get所下载的包占用的磁盘空间。

我们也可以使用“autoclean”选项来代替“clean”,两者之间主要的区别是autoclean清理不再使用且没用的下载。

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

示例:13 使用“autoremove”删除包

当在apt-get命令中使用“autoremove”时,它会删除为了满足依赖而安装且现在没用的包。

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get autoremove icinga

示例:14 显示包的更新日志

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get changelog apache2
Get:1 Changelog for apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.10-1ubuntu1/changelog) [195 kB]
Fetched 195 kB in 3s (60.9 kB/s)

上面的命令会下载apache2的更新日志,并在你屏幕上分页显示。
示例:15 使用 “check” 选项显示损坏的依赖关系

   

复制代码
代码如下:
linuxtechi@localhost:~$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done

 
标签: apt-get apt-cache
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • yum和apt-get的区别
    





		Debian 配置apt-get源
    yum和apt-get的区别 Debian 配置ap
     服务端配置1、安装apt-mirrorapt-get install apt-mirror 2、修改apt-mirror配置文件vim /etc/apt/mirror.list 参考以下配置文件:清空原有的配置文件,直接使用以下配置文件即可############# config ################### 以下注释的内容都是默认配置,
    02-10
  • Ubuntu(Debian)的aptitude与apt-get的区别和联
          最近在使用Puppet快速部署Openstack,看到一些没见过的工具,例如aptitude,在Ubuntu上有强大的apt-get为什么还要用这个呢。本文转自:http://hi.baidu.com/52safe/blog/item/c17891ff02201653d6887d96.html  起初GNU/Linux系统中只有.tar.gz。用
    02-10
  • Debian从光盘apt-get 硬盘安装debian
    vi /etc/apt/source.list 
    02-10
  • 解决Ubuntu/debian的Apt-get 由于依赖关系安装
     The following packages have unmet dependencies:  libssl-dev: Depends: libssl0.9.8 (= 0.9.8k-7ubuntu8) but 0.9.8k-7ubuntu8.5 is to be installed这个时候应该请令一个工具出马了:"aptitude"使用这个工具,当某个库依赖的库与当前版本不一致时,ap
    02-10
  • Debian apt-get 用法
    (说明:sudo--使用超级管理员权限进行apt-get ; packagename--代表安装的软件包名)sudo apt-get update —— 在修改/etc/apt/sources.list或者/etc/apt/preferences之后运行该命令。此外您需要定期运行这一命令以确保您的软件包列表是最新的。sudo apt-get  i
    02-10
  • debian apt-get联网安装mysql服务
    安装mysql和卸载mysql1.安装数据库:sudo apt-get install mysql-server 安装过程中需要设置密码。 2.安装客户端:sudo apt-get install mysql-client 3.登录MySQL:mysql -u root -p 4.配置文件:/etc/mysql/my.cnf a.设置远程访问:将bind-address = 127.0.
    02-10
  • 安装、配置MySQL5.8基于Debian 9(用apt-get install 默认安装结果是mariadb)
    安装、配置MySQL5.8基于Debian 9(用apt-get in
     地址:https://dev.mysql.com/downloads/mysql/下载如下包: 2、上传并解压tar -xvf  mysql-server_8.0.13-1debian9_amd64.deb-bundle.tar得到一堆文件如下: 3、安装由于依赖,需要按如下顺序安装先安装libaio1:apt-get install libaio1mysql-common:d
    02-10
  • Ubuntu apt-get 更换源
    我们使用清华的镜像源进行更换Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。更换源16.04 LTS# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释de
    02-10
  • Ubuntu中用sudo apt-get install makeinfo时,
    背景:       在准备ARM交叉编译环境时,执行命令:               DISTRO=fsl-imx-x11 MACHINE=imx6qsabresd source fsl-setup-release.sh -b build-x11,报错:Missing package:makeinfo,chrpath,       接着,依次执行sudo apt-get instal
    02-10
  • Ubuntu使用apt-get upgrade升级时出错
    今天在按照常规的sudo apt-get update更新软件列表后,再使用sudo apt-get upgrade升级软件时,出现了以下的错误:正在设置 linux-image-extra-4.4.0-97-generic (4.4.0-97.120) ...run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-97-g
    02-10
点击排行