惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
M
MIT News - Artificial intelligence
W
WeLiveSecurity
P
Proofpoint News Feed
A
About on SuperTechFans
S
Securelist
I
InfoQ
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 叶小钗
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
腾讯CDC
Jina AI
Jina AI
S
Schneier on Security
I
Intezer
V
Visual Studio Blog
美团技术团队
V2EX - 技术
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
罗磊的独立博客
Y
Y Combinator Blog

博客园 - Edward Xie

(转)听微软大牛们谈怎样成为优秀的工程师 深入探讨数据库可用性分组 google的搜索 4 fun 从‘和少妇成功上床’学习‘金融学’(转) osi tcpip (转)Google Wave从入门到进阶 google wave Nehalem thinkpad bios APS in Linux for Lenovo R61i good 冒泡 .net 关于DotNET的整理 幽默 思考 想整这么一套 找个地放哈备忘 UBUNTU游戏集合 mount 中文man(转) 个人收集的一些ubuntu资料
(转)aptitude
Edward Xie · 2008-05-22 · via 博客园 - Edward Xie

Apt 不止是 apt-get

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 源, 就像这种

并已经 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 有相同功能, 而且可以检测进程需要哪些缺少的文件, 自动提示用户选择安装相应的包.