免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 882 | 回复: 0
打印 上一主题 下一主题

Apt 不止是 apt-get(aptitude用法等资料) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-15 10:25 |只看该作者 |倒序浏览
ubuntu(debian)下使用 apt-get 或 synaptic(新立得) 安装软件是件很轻松的事情. 除了简单的安装软件, apt工具集还有许多特别情况下的用法.
任何时候请记住 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
apt-file [options] action [pattern]
Configuration options:
    --sources-list      -s        sources.list location
    --cache             -c         Cache directory
    --architecture      -a        Use specific architecture
    --cdrom-mount       -d       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        Search files in packages
    list|show          List files in packages
    purge                       Remove cache files
此工具在寻找编译时缺的文件时很有用, 用前记得先 apt-file update
PS: auto-apt 有相同功能, 而且可以检测进程需要哪些缺少的文件, 自动提示用户选择安装相应的包.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/59015/showart_2070756.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP