Apt使用参考:Apt不止是Apt-get

 命令 作用
apt-cache search package 搜索包
apt-cache show package 获取包的相关信息,如说明、大小、版本等
sudo apt-get install package 安装包
sudo apt-get install package - - reinstall 重新安装包
sudo apt-get -f install "-f = --fix-missing"当是修复安装吧...
sudo apt-get remove package 删除包
sudo apt-get remove package - - purge 删除包,包括删除配置文件等
sudo apt-get update 更新源
sudo apt-get upgrade 更新已安装的包
sudo apt-get dist-upgrade 升级系统
sudo apt-get dselect-upgrade 使用 dselect 升级
apt-cache depends package 了解使用依赖
apt-cache rdepends package 查看该包被哪些包依赖吧...
sudo apt-get build-dep package 安装相关的编译环境
apt-get source package 下载该包的源代码
sudo apt-get clean && sudo apt-get autoclean 清理下载文件的存档,只清理无用的包
sudo apt-get check 检查是否有损坏的依赖

ubuntu(debian)下使用 apt-get 或 synaptic(新立得) 安装软件是件很轻松的事情. 除了简单的安装软件, apt工具集还有许多特别情况下的用法.

原文地址:http://hi.baidu.com/agoods/blog/item/1933f0f207a9f716b17ec54a.html



任何时候请记住 man 手册是良师.

1. 使用 aptitude 代替 apt-get .
aptitude 虽然没有 apt-get 的"超级牛力", 但功能却比 apt-get 更强大
首先, 像 apt-get 一样, 可以安装软件
代码:
aptitude install pack-foo

aptitude 解决依赖关系比 apt-get 更智能. 有时用 apt-get 安装软件时会出现 "XXX 需要 XXXX, 但 XXX 已安装" 这类的错误. 这通常是因为某些软件包过新造成的. 此时使用 aptitude, aptitude 会发现问题并给出几个解决方案, 我们只需接受符合心意的方案就可以了.

aptitude 的另外一个优点是会自动记录那些包是"自动安装"(即因依赖关系而安装的), 如果依赖"自动安装"包的包都没被安装, 该"自动安装"包(此时已无用)就会自动删除.
使用这两个命令可以控制包的"自动安装"属性
代码:
aptitude markauto pack-foo #标记成"自动安装"
aptitude unmarkauto pack-foo #标记成"手动安装"

删除软件时使用 markauto 代替 remove, 就可以避免误删重要的包了.
当然, 新版的新立得和 apt-get 也有相似功能, 但貌似不与 aptitude 使用同一个数据库, 所以建议只使用 aptitude 管理软件包.

aptitude 还提供了更灵活的控制软件包版本的方式
代码:
hold - 将软件包置于保持状态
unhold - 取消对一个软件包的保持命令
forbid-version - 禁止 aptitude 升级到某一特定版本的软件包。

以前几周的 libcairo 事件作例子:
代码:
sudo aptitude install libcairo2=1.4.10-1ubuntu4 # 强制降级
sudo aptitude forbid-version libcairo2=1.4.10-1ubuntu4.1 # 封掉出错的版本
sudo aptitude markauto libcairo2 #恢复auto属性

参看 man 手册里对 install 操作的描述, 有更多控制方法.

aptitude reinstall 重新安装软件包, 相当于 apt-get --reinstall install
aptitude purge 彻底删除软件包, 相当于 apt-get --purge remove
一个小技巧
代码:
aptitude purge `dpkg -l|grep '^rc'|awk '{print $2}'`


aptitude 还集合了多个 apt 工具的功能
代码:
search - 按名称 和/或 表达式搜索软件包
show - 显示一个软件包的详细信息
download - 下载软件包的 .deb 文件

search 操作有点特别
代码:
aptitude search "foo bar" # 关键词 foo 和 bar 都要出现
aptitude search foo bar # 相当于"或"


不过 aptitude 有个小缺点, 默认会将"推荐"的包当成"依赖"的包处理. 这样设置一下就可以解决问题
在自己和root的家目录下的 .aptitude/config 文件加一句
代码:
aptitude::Recommends-Important "false";


更详细的用法参看 man aptitude.
另外:
1.aptitude 的交互模式貌似很混乱, 不如用新立得.
2.慎用 aptitude install -f .

2. 获得软件包的下载地址
很简单

使用新立得:
1.选中要安装的包
2.文件 -> 生成包下载脚本

使用 apt-get
代码:
apt-get --print-uris install pack-foo


3. 安装齐编译需要的包
首先确定你添加了 deb-src 源, 就像这种
代码:
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy main restricted universe multiverse

并已经 apt-get update
然后就可以
代码:
apt-get build-dep pack-foo

把编译 pack-foo 需要的包安装好

PS: 更强悍的方法是用 apt-build, 不过这样就把 ubuntu 搞的太像 gentoo 了. 有兴趣的朋友可以自己看 apt-build 的 man.

4. 找某个文件在哪个包里
如果是安装了的包, 可以用 dpkg -S, 但此法对未安装的包就无效了.
此时可使用 apt-file
代码:
$ apt-file help
apt-file version 2.0.8.2
(c) 2002 Sebastien J. Gross <sjg@debian.org>


apt-file [options] action [pattern]

Configuration options:
--sources-list -s <file> sources.list location
--cache -c <dir> Cache directory
--architecture -a <arch> Use specific architecture
--cdrom-mount -d <cdrom> Use specific cdrom mountpoint
--package-only -l Only display packages name
--fixed-string -F Do not expand pattern
--ignore-case -i Ignore case distinctions
--regexp -x pattern is a regular expression
--verbose -v run in verbose mode
--dummy -y run in dummy mode (no action)
--help -h Show this help.
--version -V Show version number

Action:
update Fetch Contents files from apt-sources.
search|find <pattern> Search files in packages
list|show <pattern> List files in packages
purge Remove cache files

此工具在寻找编译时缺的文件时很有用, 用前记得先 apt-file update

PS: auto-apt 有相同功能, 而且可以检测进程需要哪些缺少的文件, 自动提示用户选择安装相应的包。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值