[wiki]AptGetHowTo

参与到Ubuntu的翻译中来
回复
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

[wiki]AptGetHowTo

#1

帖子 oneleaf » 2005-07-22 14:18

Package management with apt

IconApt.png
Intro

In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.

A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions.

From

*

Debian APT HOWTO

Commands

All these commands require sudo!

*

apt-get update - Run this after changing /etc/apt/sources.list or /etc/apt/preferences. You also must run it periodically to make sure your source list is up-to-date.
*

apt-get install packagename - installs a new package (but see aptitude, below)
*

apt-get remove packagename - removes a installed package (configfiles remain)
*

apt-get --purge remove packagename - removes a installed package (configfiles will also be removed)
*

apt-get upgrade - upgrades all installed packages
*

apt-get dist-upgrade - upgrades the entire system to a newer release
*

apt-cache search string - Searches for string in the list of known packages
*

dpkg -l package-name-pattern - List packages matching pattern
*

aptitude - Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations.
*

apt-cache showpkg pkgs - Show information about packages.
*

apt-cache dumpavail - Prints out an available list.
*

apt-cache show pkgs - Displays package records, similar to dpkg --print-avail.
*

apt-cache pkgnames - Fast listing of every package in the system.
*

dpkg -S file - Which installed package owns the file?
*

dpkg -L package - List files in the package.
*

apt-file search filename - Search for a package (need not be installed) containing files including the string. apt-file is a package of its own, which you may have to apt-get install first, then run apt-file update. If apt-file search filename shows you too much, try apt-file search filename | grep -w filename (which shows you only the files that contain filename as a whole word) or variants like apt-file search filename | grep /bin/ only files located in directories like /bin or /usr/bin, useful if you're looking for a particular executable).

* apt-get autoclean - Run this periodically to clean out .deb archives from packages which are no longer installed on the system. You can regain lots of disk space that way. If you're really desperate for disk space, apt-get clean is more radical, and will remove .deb files even for packages currently installed. But most of the time you probably don't need the .debs any more, so it might be worth it if you're strapped for megabytes.
Additional packages

deborphan and debfoster are great for finding orphaned and unneeded packages which can be removed.
notes

You can pull from a different repository by editing /etc/apt/sources.list to replace "stable" with "unstable" (or whatever) then doing apt-get update. That gets old, though, so here's a better way: pinning. Here's a sample unstable preferences file.
Speeding up your work at the command line

The command line is powerful, but typing is slow, so make your commands shorter. You might put this in your *~/.bashrc*

alias acs='apt-cache search'
alias agu='sudo apt-get update'
alias agg='sudo apt-get upgrade'
alias agd='sudo apt-get dist-upgrade'
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'

But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'"

https://wiki.ubuntu.com/AptGetHowTo
当净其意如虚空,远离妄想及诸取,令心所向皆无碍
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#2

帖子 sigus » 2005-07-22 15:11

这篇文章我认领了,各位兄弟不要让我做费工 :oops:
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#3

帖子 sigus » 2005-07-22 18:06

使用apt来进行包裹管理
IconApt.png(应该是一张png格式的插图)
介绍
首先,.tar.gz.的用户如果希望在自己的GNU/Linux 系统下使用这些软件必须编译每个项目。Debian的诞生,使人们有理由相信这个系统拥有一种管理安装包裹(package)的方法,使得这些包裹可以安装到机器上。这个系统被叫做dpkg。由此安装包裹(package)第一次被引入到了GNU/Linux上,而此时的红帽子自己的’rpm’系统还在酝酿之中。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#4

帖子 sigus » 2005-07-22 18:07

一个新的难题挡在了GNU/Linux的设计者面前。他们需要一个快速,实效性强,并且有效率的方式来安装这些安装包裹,并且希望它能够在升级时自动而独立的配置这些安装包裹升级中的文件。在这里重申一下,Debian直接导致了APT的诞生,即Advanced Packaging Tool。 从那时起它就和rpm一起被使用在Conectiva中,同时它也被不少其他的分布式系统所采用。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#5

帖子 sigus » 2005-07-22 18:10

怎样使用Debian的APT
可使用的命令
所有的这些命令都需要sudo!
apt-get update-在改变了/etc/apt/sources.list或者/etc/apt/preferences之后运行。你也应该定期的运行它以保证你的source list是最新的。

apt-get install packagename-安装一个新的安装包裹(参见下面的aptitude行)

apt-get remove packagename-移除一个已经安装了的安装包裹(运行后configfiles仍然会留下来)
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#6

帖子 sigus » 2005-07-22 18:12

apt-get --purge remove packagename-移除一个已经安装了的安装包裹(运行后configfiles也会被删除)

apt-get upgrade-更新所有已经安装了的安装包裹

apt-get dist-upgrade-更新整个系统到一个更新的发行版本

apt-cache search string-在一系列已知的安装包裹中找寻字符串

dpkg -l package-name-pattern-列出匹配模式的安装包裹

aptitude-详细的查看已经安装或者可以使用的安装包裹。Aptitude能够使用和apt-get相类似的方式用在命令行中,但是只有一些命令可用-最常用的安装和移除命令。但是因为aptitude比起apt-get来保留了更多的跟踪信息,它在安装和移除系统时拥有更好的表现。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#7

帖子 sigus » 2005-07-22 19:10

apt-cache showpkg pkgs-显示安装包裹的信息。

apt-cache dumpavail-打印一个可用的安装包裹名单。

apt-cache show pkgs-显示安装包裹的记录,和dpkg –print-avail功能相似。

apt-cache pkgnames-快速列出每个在系统中的安装包裹。

dpkg -S file-哪个已经安装的安装包裹包含这个文件。

dpkg -L package-列出在这个包裹中所有文件。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#8

帖子 sigus » 2005-07-22 19:11

apt-file search filename-查找包含此文件名的安装包裹(不需要是已经安装的)。apt-file是一个包含自身的安装包裹。你必须先用apt-get install来安装,然后还需要运行apt-file update。如果apt-file search filename一次显示了过多的内容,使用apt-file search filename|grep –w filename(这样只会显示包含文件名字的内容)或者使用apt-file search filename|grep /bin/ 那些在固定文件夹中的文件,比如/bin或者/usr/bin,如果你查找一个特殊的执行文件的话,这会非常有帮助)。

apt-get autoclean-定期运行这个命令来清除那些已经不在你的系统中的安装包裹中的.deb文件夹。你通过这个方式能够重新获得不少的磁盘空间。如果你狂热的对磁盘空间有需求的话,apt-get clean是十分激进的,它甚至会移除那些现在已经安装了的安装包裹中的.deb文件。但是大部分的时间你不需要.debs,所以如果你为磁盘空间感到焦头烂额,运行它还是很值得的。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#9

帖子 sigus » 2005-07-22 19:15

其余的安装包裹
deborphan和debfoster是查找可以被移除的没有什么用处的安装包裹的良好工具。

注意
通过编辑/etc/apt/sources.list你能够调出一个不同的库。具体的方法是替换其中的’stable’为’unstable’(或者其他什么文字)然后运行/apt-get update。但是这种方法是一种老方法,更新的办法是pinning(销连接)。下面是一个unstable配置文件的例子。
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#10

帖子 sigus » 2005-07-22 19:16

用命令行来加速我们的工作吧,^_^
命令行是很有有效,不过打字太慢了,所以把你的命令变得更小巧吧。你最好把以下的内容输入*~/.bashrc*
alias acs='apt-cache search'
alias agu='sudo apt-get update'
alias agg='sudo apt-get upgrade'
alias agd='sudo apt-get dist-upgrade'
alias agi='sudo apt-get install'
alias agr='sudo apt-get remove'
但是看看上面有关aptitude的介绍,我们有理由使用alias agi='sudo aptitude install'来替代alias agi='sudo apt-get install'
头像
sigus
帖子: 47
注册时间: 2005-07-14 20:31

#11

帖子 sigus » 2005-07-22 19:16

本篇完毕,谢谢观赏 :D
头像
Lucia
帖子: 29
注册时间: 2005-07-15 21:19

#12

帖子 Lucia » 2005-07-22 20:58

sigus的头像好可爱哦,翻译的真快 :)
Things change......
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

#13

帖子 oneleaf » 2005-07-23 23:09

当净其意如虚空,远离妄想及诸取,令心所向皆无碍
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#14

帖子 millenniumdark » 2006-07-31 1:04

校对一遍,修改了一处,新增一处
英文加了好多新内容,有兴趣的接手
http://wiki.ubuntu.org.cn/AptGetHowTo
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

#15

帖子 millenniumdark » 2006-07-31 1:06

sigus 写了:这篇文章我认领了,各位兄弟不要让我做费工 :oops:
转到wiki上,工就不会废了。
回复