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

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos 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 有相同功能, 而且可以检测进程需要哪些缺少的文件, 自动提示用户选择安装相应的包.