第十五章 : 软件包管理
軟件包管理
?
If we spend any time in the Linux community, we hear many opinions as to which of themany Linux distributions is “best.” Often, these discussions get really silly, focusing onsuch things as the prettiness of the desktop background (some people won’t use Ubuntubecause its default color scheme is brown!) and other trivial matters.
如果我們花些時間在 Linux 社區里,我們會得知很多針對, 類如在眾多 Linux 發行版中哪個是最好的(等問題的)看法。這些討論通常變得非常可笑,都集中在一些像桌面背景的漂亮程度(一些人不使用 Ubuntu,只是因為 Ubuntu 默認主題顏色是棕色的!)和其它的瑣碎東西上。
The most important determinant of distribution quality is the packaging system and thevitality of the distribution’s support community. As we spend more time with Linux, wesee that its software landscape is extremely dynamic. Things are constantly changing.Most of the top-tier Linux distributions release new versions every six months and manyindividual program updates every day. To keep up with this blizzard of software, weneed good tools for package management.
Linux 發行版本質量最重要的決定因素是軟件包管理系統和其支持社區的持久性。隨著我們花更多的時間在 Linux 上,我們會發現它的變化是非常快的。大多數一線Linux 發行版每隔六個月發布一個新版本,并且許多獨立的程序每天都會更新。為了能和這些如暴風雪一般多的軟件保持聯系,我們需要一些好工具來進行軟件包管理。
Package management is a method of installing and maintaining software on the system.Today, most people can satisfy all of their software needs by installing packages fromtheir Linux distributor. This contrasts with the early days of Linux, when one had todownload and compile source code in order to install software. Not that there is anythingwrong with compiling source code; in fact, having access to source code is the greatwonder of Linux. It gives us (and everybody else) the ability to examine and improve thesystem. It’s just that having a pre-compiled package is faster and easier to deal with.In this chapter, we will look at some of the command line tools used for packagemanagement. While all of the major distributions provide powerful and sophisticatedgraphical programs for maintaining the system, it is important to learn about thecommand line programs, too. They can perform many tasks that are difficult (orimpossible) to do with their graphical counterparts.
軟件包管理是指系統中一種安裝和維護軟件的方法。今天,通過從 Linux 發行版中安裝的軟件包,已能滿足許多人所有的軟件需求。這不同于早期的 Linux,人們需要下載和編譯源碼來安裝軟件。編譯源碼沒有任何問題,事實上,擁有對源碼的訪問權限是 Linux 的偉大奇跡。它賦予我們(其它每個人)檢測和提高系統性能的能力。只是若有一個預先編譯好的軟件包處理起來要相對容易快速些。這章中,我們將查看一些用于包管理的命令行工具。雖然所有主流 Linux 發行版都提供了強大且精致的圖形管理程序來維護系統,但是學習命令行程序也非常重要。因為它們可以完成許多讓圖形化管理程序處理起來困難(或者不可能)的任務。
打包系統
Different distributions use different packaging systems and as a general rule, a packageintended for one distribution is not compatible with another distribution. Mostdistributions fall into one of two camps of packaging technologies: the Debian “.deb”camp and the Red Hat “.rpm” camp. There are some important exceptions such asGentoo, Slackware, and Foresight, but most others use one of these two basic systems.
不同的 Linux 發行版使用不同的打包系統,一般而言,大多數發行版分別屬于兩大包管理技術陣營:Debian 的”.deb”,和紅帽的”.rpm”。也有一些重要的例外,比方說 Gentoo,Slackware,和 Foresight,但大多數會使用這兩個基本系統中的一個。
| Debian Style (.deb) | Debian, Ubuntu, Xandros, Linspire |
| Red Hat Style (.rpm) | Fedora, CentOS, Red Hat Enterprise Linux, OpenSUSE,Mandriva, PCLinuxOS |
| Debian Style (.deb) | Debian, Ubuntu, Xandros, Linspire |
| Red Hat Style (.rpm) | Fedora, CentOS, Red Hat Enterprise Linux, OpenSUSE, Mandriva, PCLinuxOS |
軟件包管理系統是怎樣工作的
The method of software distribution found in the proprietary software industry usuallyentails buying a piece of installation media such as an “install disk” and then running an“installation wizard” to install a new application on the system.
在商業化軟件中,獲取軟件的最新版本通常需要買一張安裝媒介,比方說”安裝盤”,然后運行一個”安裝向導”,來在系統中安裝新的應用程序。
Linux doesn’t work that way. Virtually all software for a Linux system will be found onthe Internet. Most of it will be provided by the distribution vendor in the form ofpackage files and the rest will be available in source code form that can be installedmanually. We’ll talk a little about how to install software by compiling source code in alater chapter.
Linux 不是這樣。Linux 系統中幾乎所有的軟件都可以在互聯網上找到。其中大多數軟件由發行商以包文件的形式提供,剩下的則以源碼形式存在,可以手動安裝。在后面章節里,我們將會談談怎樣通過編譯源碼來安裝軟件。
包文件
The basic unit of software in a packaging system is the package file. A package file is acompressed collection of files that comprise the software package. A package mayconsist of numerous programs and data files that support the programs. In addition to thefiles to be installed, the package file also includes metadata about the package, such as atext description of the package and its contents. Additionally, many packages containpre- and post-installation scripts that perform configuration tasks before and after thepackage installation.
在包管理系統中軟件的基本單元是包文件。包文件是一個構成軟件包的文件壓縮集合。一個軟件包可能由大量程序以及支持這些程序的數據文件組成。除了安裝文件之外,軟件包文件也包括關于這個包的元數據,如軟件包及其內容的文本說明。另外,許多軟件包還包括預安裝和安裝后腳本,這些腳本用來在軟件安裝之前和之后執行配置任務。
Package files are created by a person known as a package maintainer, often (but notalways) an employee of the distribution vendor. The package maintainer gets thesoftware in source code form from the upstream provider (the author of the program),compiles it, and creates the package metadata and any necessary installation scripts.Often, the package maintainer will apply modifications to the original source code toimprove the program’s integration with the other parts of the Linux distribution.
軟件包文件是由軟件包維護者創建的,他通常是(但不總是)一名軟件發行商的雇員。軟件維護者從上游提供商(程序作者)那里得到軟件源碼,然后編譯源碼,創建軟件包元數據以及所需要的安裝腳本。通常,軟件包維護者要把所做的修改應用到最初的源碼當中,來提高此軟件與 Linux發行版其它部分的融合性。
資源庫
While some software projects choose to perform their own packaging and distribution,most packages today are created by the distribution vendors and interested third parties.Packages are made available to the users of a distribution in central repositories that maycontain many thousands of packages, each specially built and maintained for thedistribution.
雖然某些軟件項目選擇執行他們自己的打包和發布策略,但是現在大多數軟件包是由發行商和感興趣的第三方創建的。系統發行版的用戶可以在一個中心資源庫中得到這些軟件包,這個資源庫可能包含了成千上萬個軟件包,每一個軟件包都是專門為這個系統發行版建立和維護的。
A distribution may maintain several different repositories for different stages of thesoftware development life cycle. For example, there will usually be a “testing”repository that contains packages that have just been built and are intended for use bybrave souls who are looking for bugs before they are released for general distribution. Adistribution will often have a “development” repository where work-in-progress packagesdestined for inclusion in the distribution’s next major release are kept.
因軟件開發生命周期不同階段的需要,一個系統發行版可能維護著幾個不同的資源庫。例如,通常會有一個”測試”資源庫,其中包含剛剛建立的軟件包,它們想要勇敢的用戶來使用,在這些軟件包正式發布之前,讓用戶查找錯誤。系統發行版經常會有一個”開發”資源庫,這個資源庫中保存著注定要包含到下一個主要版本中的半成品軟件包。
A distribution may also have related third-party repositories. These are often needed tosupply software that, for legal reasons such as patents or DRM anti-circumvention issues,cannot be included with the distribution. Perhaps the best known case is that ofencrypted DVD support, which is not legal in the United States. The third-partyrepositories operate in countries where software patents and anti-circumvention laws donot apply. These repositories are usually wholly independent of the distribution theysupport and to use them, one must know about them and manually include them in theconfiguration files for the package management system.
一個系統發行版可能也會擁有相關第三方的資源庫。這些資源庫需要支持一些因法律原因,比如說專利或者是 DRM 反規避問題,而不能被包含到發行版中的軟件。可能最著名的案例就是對加密DVD的播放支持,在美國這是不合法的。第三方資源庫在一些軟件專利和反規避法案不生效的國家中設立并分發資源。這些資源庫通常完全地獨立于它們所支持的資源庫,要想使用它們,你必須了解它們,手動地把它們包含到軟件包管理系統的配置文件中。
依賴性
Programs seldom stand alone; rather, they rely on the presence of other softwarecomponents to get their work done. Common activities, such as input/output forexample, are handled by routines shared by many programs. These routines are stored inwhat are called shared libraries, which provide essential services to more than oneprogram. If a package requires a shared resource such as a shared library, it is said tohave a dependency. Modern package management systems all provide some method ofdependency resolution to ensure that when a package is installed, all of its dependenciesare installed, too.
程序很少獨立工作;他們需要依靠其他程序的組件來完成他們的工作。程序所共有的活動,如輸入/輸出,就是由一個被多個程序調用的子例程處理的。這些子例程存儲在動態鏈接庫中。動態鏈接庫為多個程序提供基本服務。如果一個軟件包需要一些共享的資源,如一個動態鏈接庫,它就被稱作有一個依賴。現代的軟件包管理系統都提供了一些依賴項解析方法,以確保安裝軟件包時,其所有的依賴也被安裝。
上層和底層軟件包工具
Package management systems usually consist of two types of tools: low-level tools whichhandle tasks such as installing and removing package files, and high-level tools thatperform metadata searching and dependency resolution. In this chapter, we will look atthe tools supplied with Debian-style systems (such as Ubuntu and many others) and thoseused by recent Red Hat products. While all Red Hat-style distributions rely on the samelow-level program (rpm), they use different high-level tools. For our discussion, we willcover the high-level program yum, used by Fedora, Red Hat Enterprise Linux, andCentOS. Other Red Hat-style distributions provide high-level tools with comparablefeatures.
軟件包管理系統通常由兩種工具類型組成:底層工具用來處理這些任務,比方說安裝和刪除軟件包文件,和上層工具,完成元數據搜索和依賴解析。在這一章中,我們將看一下由 Debian 風格的系統(比如說 Ubuntu,還有許多其它系統)提供的工具,還有那些由 RedHat 產品使用的工具。雖然所有基于 Red Hat 風格的發行版都依賴于相同的底層程序(rpm),但是它們卻使用不同的上層工具。在我們的討論中,我們將研究Fedora, RedHat 企業版,和 CentOs所使用的 yum 。其它Red Hat 風格的發行版提供了帶有類似yum的其他上層工具。
| Debian-Style | dpkg | apt-get, aptitude |
| Fedora, Red Hat Enterprise Linux, CentOS | rpm | yum |
| Debian-Style | dpkg | apt-get, aptitude |
| Fedora, Red Hat Enterprise Linux, CentOS | rpm | yum |
常見軟件包管理任務
There are many operations that can be performed with the command line packagemanagement tools. We will look at the most common. Be aware that the low-level toolsalso support creation of package files, an activity outside the scope of this book.In the discussion below, the term “package_name” refers to the actual name of apackage rather than the term “package_file,” which is the name of the file thatcontains the package.
通過命令行軟件包管理工具可以完成許多操作。我們將會看一下最常用的工具。注意底層工具也支持軟件包文件的創建,這個話題超出了本書敘述的范圍。在以下的討論中,”package_name”這個術語是指軟件包實際名稱,而不是指”package_file”,它是包含在軟件包中的文件名。
查找資源庫中的軟件包
Using the high-level tools to search repository metadata, a package can be located basedon its name or description.
使用上層工具來搜索資源庫元數據,可以根據軟件包的名字和說明來定位它。
| Debian | apt-get update; apt-cache search search_string |
| Red Hat | yum search search_string |
| Debian | apt-get update; apt-cache search search_string |
| Red Hat | yum search search_string |
Example: To search a yum repository for the emacs text editor, this command could beused:
例如:搜索一個 yum 資源庫來查找 emacs 文本編輯器,使用以下命令:
yum search emacs從資源庫中安裝一個軟件包
High-level tools permit a package to be downloaded from a repository and installed withfull dependency resolution.
上層工具允許從一個資源庫中下載一個軟件包,并經過完全依賴解析來安裝它。
| Debian | apt-get update; apt-get install package_name |
| Red Hat | yum install package_name |
| Debian | apt-get update; apt-get install package_name |
| Red Hat | yum install package_name |
Example: To install the emacs text editor from an apt repository:
例如:從一個 apt 資源庫來安裝 emacs 文本編輯器:
apt-get update; apt-get install emacs通過軟件包文件來安裝軟件
If a package file has been downloaded from a source other than a repository, it can beinstalled directly (though without dependency resolution) using a low-level tool.
如果從某處而不是從資源庫中下載了一個軟件包文件,可以使用底層工具來直接(沒有經過依賴解析)安裝它。
| Debian | dpkg --install package_file |
| Red Hat | rpm -i package_file |
| Debian | dpkg --install package_file |
| Red Hat | rpm -i package_file |
Example: If the emacs-22.1-7.fc7-i386.rpm package file had been downloadedfrom a non-repository site, it would be installed this way:
例如:如果已經從一個并非資源庫的網站下載了軟件包文件 emacs-22.1-7.fc7-i386.rpm,則可以通過這種方法來安裝它:
rpm -i emacs-22.1-7.fc7-i386.rpmNote: Since this technique uses the low-level rpm program to perform theinstallation, no dependency resolution is performed. If rpm discovers a missingdependency, rpm will exit with an error.
注意:因為這項技術使用底層的 rpm 程序來執行安裝任務,所以沒有運行依賴解析。如果 rpm 程序發現缺少了一個依賴,則會報錯并退出。
卸載軟件
Packages can be uninstalled using either the high-level or low-tools. The high-level toolsare shown below.
可以使用上層或者底層工具來卸載軟件。下面是可用的上層工具。
| Debian | apt-get remove package_name |
| Red Hat | yum erase package_name |
| Debian | apt-get remove package_name |
| Red Hat | yum erase package_name |
Example: To uninstall the emacs package from a Debian-style system:
例如:從 Debian 風格的系統中卸載 emacs 軟件包:
apt-get remove emacs經過資源庫來更新軟件包
The most common package management task is keeping the system up-to-date with thelatest packages. The high-level tools can perform this vital task in one single step.
最常見的軟件包管理任務是保持系統中的軟件包都是最新的。上層工具僅需一步就能完成這個至關重要的任務。
| Debian | apt-get update; apt-get upgrade |
| Red Hat | yum update |
| Debian | apt-get update; apt-get upgrade |
| Red Hat | yum update |
Example: To apply any available updates to the installed packages on a Debian-stylesystem:
例如:更新安裝在 Debian 風格系統中的軟件包:
apt-get update; apt-get upgrade經過軟件包文件來升級軟件
If an updated version of a package has been downloaded from a non-repository source, itcan be installed, replacing the previous version:
如果已經從一個非資源庫網站下載了一個軟件包的最新版本,可以安裝這個版本,用它來替代先前的版本:
| Debian | dpkg --install package_file |
| Red Hat | rpm -U package_file |
| Debian | dpkg --install package_file |
| Red Hat | rpm -U package_file |
Example: Updating an existing installation of emacs to the version contained in thepackage file emacs-22.1-7.fc7-i386.rpm on a Red Hat system:
例如:把 Red Hat 系統中所安裝的 emacs 的版本更新到軟件包文件 emacs-22.1-7.fc7-i386.rpmz 所包含的 emacs 版本。
rpm -U emacs-22.1-7.fc7-i386.rpmNote: dpkg does not have a specific option for upgrading a package versusinstalling one as rpm does.
注意:rpm 程序安裝一個軟件包和升級一個軟件包所用的選項是不同的,而 dpkg 程序所用的選項是相同的。
列出所安裝的軟件包
These commands can be used to display a list of all the packages installed on the system:
下表中的命令可以用來顯示安裝到系統中的所有軟件包列表:
| Debian | dpkg --list |
| Red Hat | rpm -qa |
| Debian | dpkg --list |
| Red Hat | rpm -qa |
確定是否安裝了一個軟件包
These low-level tools can be used to display whether a specified package is installed:
這些底端工具可以用來顯示是否安裝了一個指定的軟件包:
| Debian | dpkg --status package_name |
| Red Hat | rpm -q package_name |
| Debian | dpkg --status package_name |
| Red Hat | rpm -q package_name |
Example: To determine if the emacs package is installed on a Debian style system:
例如:確定是否 Debian 風格的系統中安裝了這個 emacs 軟件包:
dpkg --status emacs顯示所安裝軟件包的信息
If the name of an installed package is known, the following commands can be used todisplay a description of the package:
如果知道了所安裝軟件包的名字,使用以下命令可以顯示這個軟件包的說明信息:
| Debian | apt-cache show package_name |
| Red Hat | yum info package_name |
| Debian | apt-cache show package_name |
| Red Hat | yum info package_name |
Example: To see a description of the emacs package on a Debian-style system:
例如:查看 Debian 風格的系統中 emacs 軟件包的說明信息:
apt-cache show emacs查找安裝了某個文件的軟件包
To determine what package is responsible for the installation of a particular file, thefollowing commands can be used:
確定哪個軟件包對所安裝的某個特殊文件負責,使用下表中的命令:
| Debian | dpkg --search file_name |
| Red Hat | rpm -qf file_name |
| Debian | dpkg --search file_name |
| Red Hat | rpm -qf file_name |
Example: To see what package installed the /usr/bin/vim file on a Red Hat system:
例如:在 Red Hat 系統中,查看哪個軟件包安裝了/usr/bin/vim 這個文件
rpm -qf /usr/bin/vim總結歸納
In the chapters that follow, we will explore many different programs covering a widerange of application areas. While most of these programs are commonly installed bydefault, we may need to install additional packages if necessary programs are not alreadyinstalled on our system. With our newfound knowledge (and appreciation) of packagemanagement, we should have no problem installing and managing the programs we need.
在隨后的章節里面,我們將探討許多不同的程序,這些程序涵蓋了廣泛的應用程序領域。雖然大多數程序一般是默認安裝的,但是若所需程序沒有安裝在系統中,那么我們可能需要安裝額外的軟件包。通過我們新學到的(和了解的)軟件包管理知識,我們應該能夠安裝和管理所需程序。
The Linux Software Installation Myth
Linux 軟件安裝謠言
People migrating from other platforms sometimes fall victim to the myth thatsoftware is somehow difficult to install under Linux and that the variety ofpackaging schemes used by different distributions is a hindrance. Well, it is ahindrance, but only to proprietary software vendors who wish to distribute binary-only versions of their secret software.
從其它平臺遷移過來的用戶有時會成為謠言的受害者,說是在 Linux 系統中,安裝軟件有些困難,并且不同系統發行版所使用的各種各樣的打包方案是一個障礙。唉,它是一個障礙,但只是針對于那些希望把他們的秘密軟件只以二進制版本發行的專有軟件供應商。
The Linux software ecosystem is based on the idea of open source code. If aprogram developer releases source code for a product, it is likely that a personassociated with a distribution will package the product and include it in theirrepository. This method ensures that the product is well integrated into thedistribution and the user is given the convenience of “one-stop shopping” forsoftware, rather than having to search for each product’s web site.
Linux 軟件生態系統是基于開放源代碼理念。如果一個程序開發人員發布了一款產品的源碼,那么與系統發行版相關聯的開發人員可能就會把這款產品打包,并把它包含在他們的資源庫中。這種方法保證了這款產品能很好地與系統發行版整合在一起,同時為用戶“一站式采購”軟件提供了方便,從而用戶不必去搜索每個產品的網站。
Device drivers are are handled in much the same way, except that instead of beingseparate items in a distribution’s repository, they become part of the Linux kernelitself. Generally speaking, there is no such thing as a “driver disk” in Linux.Either the kernel supports a device or it doesn’t, and the Linux kernel supports alot of devices. Many more, in fact, than Windows does. Of course, this is of noconsolation if the particular device you need is not supported. When thathappens, you need to look at the cause. A lack of driver support is usually causedby one of three things:
設備驅動差不多也以同樣的方式來處理,但它們不是系統發行版資源庫中單獨的項目,它們本身是 Linux 系統內核的一部分。一般來說,在 Linux 當中沒有一個類似于“驅動盤”的東西。Linux內核要么支持一個設備,要不就不支持。Linux 內核支持很多設備,事實上,Linux支持的設備數目多于 Windows所支持的。當然,萬一你需要的特定設備不被Linux支持,也于事無補。當那種情況發生時,你需要查找一下原因。缺少驅動程序支持通常是由以下三種情況之一導致:
The device is too new. Since many hardware vendors don’t actively supportLinux development, it falls upon a member of the Linux community to write thekernel driver code. This takes time.
The device is too exotic. Not all distributions include every possible devicedriver. Each distribution builds their own kernels, and since kernels are veryconfigurable (which is what makes it possible to run Linux on everything fromwristwatches to mainframes) they may have overlooked a particular device. Bylocating and downloading the source code for the driver, it is possible for you(yes, you) to compile and install the driver yourself. This process is not overlydifficult, but it is rather involved. We’ll talk about compiling software in a laterchapter.
The hardware vendor is hiding something. They have neither releasedsource code for a Linux driver, nor have they released the technicaldocumentation for somebody to create one for them. This means that thehardware vendor is trying to keep the programming interfaces to the device asecret. Since we don’t want secret devices in our computers, I suggest that youremove the offending hardware and pitch it into the trash, with your other uselessitems.
設備太新。 因為許多硬件供應商沒有積極地支持 Linux 的發展,那么編寫內核驅動代碼的任務就由一些 Linux 社區來承擔,而這需要花費時間。
設備太奇異。 不是所有的發行版都包含每個可能的設備驅動。每個發行版會建立它們自己的內核,因為內核是可以配置的(這使得從手表到主機的每臺設備上運行 Linux 成為可能),這樣它們可能會忽略某個特殊設備。通過定位和下載驅動程序的源碼,可能需要你自己(是的,由你)來編譯和安裝驅動。這個過程不是很難,而是需要參與的。我們將在隨后的章節里來討論編譯軟件。
硬件供應商隱藏信息。 他們既不發布應用于 Linux 系統的驅動程序代碼,也不發布技術文檔來讓某人創建它。這意味著硬件供應商試圖保密此設備的程序接口。因為我們不想在計算機中使用保密的設備,所以我建議刪除這令人厭惡的硬件,把它和其它無用的東西都仍到垃圾桶里。
拓展閱讀
Spend some time getting to know the package management system for your distribution.Each distribution provides documentation for its package management tools. In addition,here are some more generic sources:
花些時間來了解你所用發行版中的軟件包管理系統。每個發行版都提供了關于自帶軟件包管理工具的文檔。另外,這里有一些更普遍的資源:
-
The Debian GNU/Linux FAQ chapter on package management provides anoverview of package management on Debian systems :
-
Debian GNU/Linux FAQ 關于軟件包管理一章對軟件包管理進行了概述:
http://www.debian.org/doc/FAQ/ch-pkgtools.en.html
-
The home page for the RPM project:
-
RPM 工程的主頁:
http://www.rpm.org
-
The home page for the YUM project at Duke University:
-
杜克大學 YUM 工程的主頁:
http://linux.duke.edu/projects/yum/
-
For a little background, the Wikipedia has an article on metadata:
-
了解一點兒背景知識,Wikipedia 上有一篇關于 metadata 的文章:
http://en.wikipedia.org/wiki/Metadata
?
返回專欄???????
==================================Talk is cheap, show me the code================================
轉載于:https://www.cnblogs.com/lcy0515/p/10807917.html
總結
以上是生活随笔為你收集整理的第十五章 : 软件包管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3gp格式如何进行转换呢
- 下一篇: 平衡方案