个人工具

“Quick HOWTO : Ch06 : Installing Linux Software/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
总结
 
(未显示1个用户的15个中间版本)
第1行: 第1行:
{{Translation}}
+
{{Copyedit translation}}
 
{{From|http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch06_:_Installing_Linux_Software}}
 
{{From|http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch06_:_Installing_Linux_Software}}
 
{{Translator|[[User:麻辣丝瓜 | 麻辣丝瓜]]}}
 
{{Translator|[[User:麻辣丝瓜 | 麻辣丝瓜]]}}
第7行: 第7行:
 
当你第一次在你的Linux服务器上安装操作系统的时候,你常常需要安装一些你认为不需要的额外的软件。这可能是因为新的业务需要更多的软件包,或者是因为要安装新的管理工具来简化你的工作。
 
当你第一次在你的Linux服务器上安装操作系统的时候,你常常需要安装一些你认为不需要的额外的软件。这可能是因为新的业务需要更多的软件包,或者是因为要安装新的管理工具来简化你的工作。
  
当Linux开发人员制作它们的软件的时候,它们总是将所有的可执行文件和数据文件捆绑在一起,从而形成一个叫做“包”的文件。包文件有许多种不同的格式,文件里有不同的控制文件。控制文件决定了包中其余文件应被放置的位置、拥有的权限以及整个包想要正常工作所依赖的包。这些信息中的一部分可能也储存你计算机中的一个数据库中,包管理软件可以使用它们来安装软件从而来加强自己的管理功能。
+
当Linux开发人员制作它们的软件的时候,它们总是将所有的可执行文件和数据文件捆绑在一起,从而形成一个叫做“软件包”的文件。包文件有许多种不同的格式,文件里有不同的控制文件。控制文件决定了软件包中其余文件应被放置的位置、拥有的权限以及整个软件包想要正常工作所依赖的软件包。这些信息中的一部分可能也储存你计算机中的一个数据库中,包管理软件可以使用它们来安装软件从而来加强自己的管理功能。
  
Redhat、Centos 和Fedora下的软件主要是用RedHat Package Manager (RPM) 文件。RPM包通常被用于在还没有定制内核或者管理程序的系统中安装软件。在部门服务器中这种情况经常发生。当因为效率或功能问题,来定制内核以增减对特定设备或特性的支持时,会使用源RPM。安装源RPM这一过程包括重新编译源代码,以使之适应定制内核的需求。这也可以方便制作包的软件开发者,现在他只需要制作一个包就可以支持不同类型的定制内核。不同的包都使用标准命令来安装其中的软件,这使得RPM包相对来说容易使用。
+
Redhat、Centos 和Fedora下的软件主要是用RedHat Package Manager (RPM) 文件。RPM软件包通常被用于在还没有定制内核或者管理程序的系统中安装软件。在部门服务器中这种情况经常发生。当因为效率或功能问题,来定制内核以增减对特定设备或特性的支持时,会使用源RPM。安装源RPM这一过程包括重新编译源代码,以使之适应定制内核的需求。这也可以方便制作包的软件开发者,现在他只需要制作一个包就可以支持不同类型的定制内核。不同的包都使用标准命令来安装其中的软件,这使得RPM包相对来说容易使用。
  
Debian和Ubuntu这两个Linux发行版使用Debian格式的包。此包的文件名是以“.deb”结尾的。也因为如此,我们通常称它们为DEB文件。
+
Debian和Ubuntu这两个Linux发行版使用Debian格式的软件包。此软件包的文件名是以“.deb”结尾的。也因为如此,我们通常称它们为DEB文件。
  
想要使用universal认证的文件格式从而使它们的产品在所有的Linux发行版中通用的程序员,也需要将他们的作品制作成TAR包。TAR包一般比RPM包难用,因为包中的文件可能需要也可能不需要编译,而且不同的包安装软件的命令也可能不同。TAR包中通常会有使用说明书来指导安装。
+
想要使用universal认证的文件格式从而使其产品在所有的Linux发行版中通用的程序员,也需要将他们的作品制作成TAR包。TAR包一般比RPM包难用,因为包中的文件可能需要也可能不需要编译,而且不同的包安装软件的命令也可能不同。TAR包中通常会有使用说明书来指导安装。
  
Linux程序员经常使用Perl语言写程序。Perl需要一些特定的库或“模块”才能正常工作,而许多Linux发布版只安装了最常用的模块。有时候在安装你的包之前,首先要先安装额外的Perl模块。知道如何安装Perl模块是Linux系统管理员技能的一个重要的组成部分。
+
Linux程序员经常使用Perl语言写程序。Perl需要一些特定的库或“模块”才能正常工作,而许多Linux发布版只安装了最常用的模块。有时候在安装你的软件包之前,首先要先安装额外的Perl模块。知道如何安装Perl模块是Linux系统管理员技能的一个重要的组成部分。
  
 
本章致力于RPM和DEB格式,它们使用于大部分的安装文件中。TAR包和Perl模块很少使用,但是它们仍是重要的软件安装工具,它们将在最后面的一个小节有所交代。
 
本章致力于RPM和DEB格式,它们使用于大部分的安装文件中。TAR包和Perl模块很少使用,但是它们仍是重要的软件安装工具,它们将在最后面的一个小节有所交代。
  
 +
=何处获得常用软件包=
  
 +
软件包有三种常用来源:发行光盘;通过浏览器、FTP客户端或者wget工具手动下载;自动下载。每种方法在这里都有所介绍,但是更加详细的将会在后续章节中介绍。
  
=Where to Get Commonly Used Packages=
+
==安装光盘中的软件包==
 +
用发行光盘安装总是比从远程网站下载来安装要容易。但是时间长了,发行光盘就不是最新版的了。稍后,我们将更加详细的讨论这种方法。
  
There are three commonly used sources for packages; distribution CDs; packages manually downloaded via a browser, File Transfer Protocol (FTP) client, or the wget utility; and automated downloads. Each of these methods is introduced here, but is covered in greater detail in sections to follow.
+
==手动下载软件包==
==Packages on Your Installation CDs==
+
获取软件包最常见的两种方法是通过FTP或浏览器手动下载。表6-1列举了一些常用的下载站点。记住,RPM的版本和你机器上运行的Linux的发行版和版本要匹配。
Installing from your distribution CDs is usually easier than having to download files from a remote Web site, but they are never up to date for very long. We discuss using this method in more detail later.
+
==Manually Downloaded Packages==
+
The two most common ways of getting packages are by manually using FTP or a Web browser. Table 6-1 lists some common download sites that can be used. Remember to match the RPM to the distribution and version of Linux your system is running.
+
  
===Table 6-1 Popular Package Download Sites===
+
===表6-1包常用下载网站===
  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
|-
 
|-
! style="background:#008000;color:white" | Distribution
+
! style="background:#008000;color:white" | 发行版
! style="background:#008000;color:white" | Location
+
! style="background:#008000;color:white" | 地址
 
|-
 
|-
 
|Redhat||http://www.redhat.com/
 
|Redhat||http://www.redhat.com/
第49行: 第49行:
 
|}
 
|}
  
'''Note:''' With Fedora you can also download packages from the download.fedora.redhat.com site. Start your search in the /pub/fedora/linux/core/ directory and move down the directory tree. If you're new to FTP, don't worry, it's explained later.
+
'''注意:''' 如果使用Fedora,你也可以从download.fedora.redhat.com下载软件包。在/pub/fedora/linux/core/路径中搜索,然后下移路径树。如果你是第一次使用FTP,别担心,稍后会有所介绍。
  
==Automated Package Download==
+
==自动下载软件包==
The disadvantage of manual downloads is that the packages often won't install unless certain prerequisite packages have been installed beforehand. This can lead to the download and installation of several packages which can become tedious.
+
手动下载的缺点是软件包通常不能安装,除非它的依赖软件包已经事先装好了。这可能会导致要下载并安装很多软件包,而这会很乏味。
  
All the major Linux distributions have automated download and update utilities. For example, Fedora uses yum and Ubuntu and Debian use apt. These are all covered in greater detail in sections to follow.
+
所有主要的Linux发行版都有自动下载更新的工具软件。比如,Fedora用yum而Ubuntu和Debian用apt。它们在接下来的章节都有更详细的介绍。
  
=How to Download Software=
+
=如何下载软件=
One of the most universally performed tasks by Linux systems administrators is the downloading of software. It is usually very simple to do and the most commonly used methods are covered in this section.
+
下载软件是Linux系统管理员最经常要做的事情。这通常非常简单。这节将介绍最常用的几种方法。
==Getting Software Using Web-Based FTP==
+
==用基于web的FTP获取软件==
There are numerous Web sites that provide links to software you can download. The methodology to get the software is usually the same for all:
+
有很多网站都提供软件的链接,你可以通过它们下载软件。获取软件的这种方法通常是相同的:
*Browse the desired Web site until you find the link to the software package you need.
+
*浏览网站,直到你找到要的软件包的链接。
*Click on the link for the desired software package.
+
*点击想要的软件包的链接。
*Save the file to your hard drive
+
*将那个文件保存在你的硬盘上。
Some web browsers, such as Firefox, will automatically download the file to your desktop, but where is the desktop? In Linux, your desktop is usually a sub-directory named Desktop located in your home or ~ directory. Here we see that the root user's desktop already contains a downloaded RPM file.
+
有的浏览器,比如Firefox,会自动地将文件下载到你的桌面上,那桌面在哪里呢?在Linux里,桌面通常是一个在你的home或~目录下的一个叫Desktop(桌面)的子目录。在这里我们可以看到,在根用户的桌面上已经有一个下载下来的RPM文件。
  
 
   [root@bigboy tmp]# cd ~/Desktop/
 
   [root@bigboy tmp]# cd ~/Desktop/
第72行: 第72行:
 
   [root@bigboy Desktop]#
 
   [root@bigboy Desktop]#
  
== Getting RPMs Using Command-Line Anonymous FTP ==
+
== 用命令行匿名FTP获取软件==
  
The Web based method above transparently uses anonymous File Transfer Protocol (FTP). Anonymous FTP allows you to log in and download files from a FTP server using the username anonymous or the shorter username ftp and a password that matches your e-mail address. This way anyone can access the data. Let's illustrate this with an example of using anonymous FTP to download the SSH package from download.fedora.redhat.com:
+
上面介绍的基于web的方法显然是使用匿名文件传输协议(FTP)。匿名FTP使你使用匿名用户名或更短的用户名ftp和符合你e-mail地址的密码,就可以登录FTP服务器并下载文件。任何人都可以通过这种方法获取数据。我们可以用一个用匿名FTP从download.fedora.redhat.com下载SSH软件包的例子来说明:
  
1) First we issue the FTP command targeting download.fedora.redhat.com at the command line.
+
1)首先我们在命令行中向download.fedora.redhat.com发出FTP命令。
  
 
  [root@bigboy tmp]# ftp download.fedora.redhat.com
 
  [root@bigboy tmp]# ftp download.fedora.redhat.com
第96行: 第96行:
 
  ftp>
 
  ftp>
  
2) After we've logged in, we can use the help command to see what options we have at our disposal.
+
2)登录成功后,我们可以用help命令来查看我们可以做的事情。
  
 
  ftp> help
 
  ftp> help
 
  Commands may be abbreviated.  Commands are:
 
  Commands may be abbreviated.  Commands are:
   
+
  (命令可能是缩写形式,有如下命令:)
 
  !              cr              mdir            proxy          send
 
  !              cr              mdir            proxy          send
 
  $              delete          mget            sendport        site
 
  $              delete          mget            sendport        site
第119行: 第119行:
 
  ftp>
 
  ftp>
 
   
 
   
The commands you'll most likely use are listed in Table 6-2:
+
表6-2列举了一些常用命令:
  
  
=== Table 6-2 FTP Commands ===
+
=== 表6-2 FTP命令===
  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
|-
 
|-
! style="background:#008000;color:white" | Command
+
! style="background:#008000;color:white" | 命令
! style="background:#008000;color:white" | Description
+
! style="background:#008000;color:white" | 描述
 
|-
 
|-
|binary||Copy files in binary mode
+
|binary||在二进制模式下拷贝文件
 
|-
 
|-
|cd||Change directory on the FTP server
+
|cd||改变FTP服务器上的目录
 
|-
 
|-
|dir||List the names of the files in the current remote directory
+
|dir||列出当前远程目录里的文件的名称
 
|-
 
|-
|exit||Bye bye
+
|exit||退出
 
|-
 
|-
|get||Get a file from the FTP server
+
|get||从FTP服务器获取文件
 
|-
 
|-
|lcd||Change the directory on the local machine
+
|lcd||改变本地计算机上的目录
 
|-
 
|-
|ls||Same as dir
+
|ls||同dir
 
|-
 
|-
|mget||Same as get, but you can use wildcards like "*"
+
|mget||同get,但是你可以使用如“*”的通配符
 
|-
 
|-
|mput||Same as put, but you can use wildcards like "*"
+
|mput||同put,但是你可以使用如“*”的通配符
 
|-
 
|-
|passive||Make the file transfer passive mode
+
|passive||使文件传输为被动模式
 
|-
 
|-
|put||Put a file from the local machine onto the FTP server
+
|put||将本地计算机上的文件上传到FTP服务器
 
|-
 
|-
|pwd||Give the directory name on the local machine
+
|pwd||获取本地计算机的目录名
 
|-
 
|-
 
|}
 
|}
  
3) By using the Web browsing feature on the Web site ahead of time, I know that the Fedora Core 2 RPMs are located in the pub/fedora/linux/core/2/i386/os/Fedora/RPMS/ directory and will use the cd command to change my directory to there. We can use the ls command to get a listing of files in this directory.
+
3)通过之前对网站上网页的浏览,我们可以知道Fedora Core 2 RPM包在pub/fedora/linux/core/2/i386/os/Fedora/RPMS/目录下。我们将使用cd命令将我们的目录改变到那里去。然后我们可以使用ls命令来获取那个目录下的文件的列表。
  
 
  ftp> cd pub/fedora/linux/core/2/i386/os/Fedora/RPMS/
 
  ftp> cd pub/fedora/linux/core/2/i386/os/Fedora/RPMS/
第170行: 第170行:
 
  ftp>
 
  ftp>
  
4) Next we get the file we need and place it in the local directory /usr/rpm. The hash command will print "#" hash signs on the screen during the download.
+
4)接下来,我们下载我们需要的文件并将其放置于本地的/usr/rpm目录下。hash命令会在下载时,在屏幕上打印井号“#”。
  
 
  ftp> hash
 
  ftp> hash
第185行: 第185行:
 
   ftp>
 
   ftp>
  
'''Note:''' You can also use wildcards to download the RPMs you need using the mget command. You'll be prompted for each of the matching RPM files. In the next example, we just aborted this download by typing n.
+
'''注意:''' 你也可以使用mget命令,从而在下载RPM时使用通配符。计算机会提示你每个符合的RPM文件名。在下个例子中,我通过键入n来中断这个下载。
  
 
  ftp> mget openssh-3.6*
 
  ftp> mget openssh-3.6*
第191行: 第191行:
 
  ftp>
 
  ftp>
  
5) Finally we use the exit command to leave FTP.
+
5)最后我们用exit命令退出FTP
  
 
  ftp> exit
 
  ftp> exit
第197行: 第197行:
 
  root@bigboy tmp]#
 
  root@bigboy tmp]#
  
== Getting Software Using wget ==
+
== 用wget获取软件==
  
The wget command can be used to download files quickly when you already know the URL at which the RPM is located. This is especially convenient if you are logged into your Linux box from another machine running a Web browser. You can browse the download site for the RPM you need, right click on the desired link and select copy shortcut (Windows) or Copy Link Location (Linux). After you have done this, you can then select your SSH/telnet/Linux Terminal login window and type in the command wget URL. Here is an example downloading a DHCP update from Fedora.
+
当你已经知道RPM的URL地址时,你可以使用wget很快地下载该文件。如果你在别机器上通过浏览器登录到了Linux系统中,这种方法尤为方便。你可以浏览下载网站来找到你要的RPM,右键点击其链接然后选择复制快捷方式(Windows)或者复制链接位置(Linux)。这一步完成后,你然后可以选择你的SSH/telnet/Linux终端登录窗口然后键入wget URL命令。这里有一个从Fedora下载DHCP更新的例子。
  
 
  [root@bigboy tmp]# wget http://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm
 
  [root@bigboy tmp]# wget http://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm
第218行: 第218行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
=Installing Software From RPM Files=
+
=用DEB软件包安装软件=
  
The Fedora, Redhat and Centos versions of Linux rely heavily upon the use of software packages in the RPM format. This section covers some of the most important topics required for you to master their use.
+
不像Redhat、Fedora和Centos这样的Linux发行版使用RPM包,Debian和Ubuntu使用的是DEB格式的软件包。此章节将讲解掌握其用法的几个最重要的问题。
  
 +
==如何手动安装DEB==
 +
总的来说,手动安装DEB文件有两种方法。其一是使用你事先下载到硬盘上的文件,其二是使用像光盘这样的移动存储来安装。
  
 
+
===用下载的文件===
== How To Install RPMs Manually ==
+
将DEB文件(通常有一个后缀名“.deb”)下载到一个临时路径,比如/tmp。第二步是用dpkg --install命令来安装该软件包。下面有一个安装ndiswrapper utilities包的例子,是典型的用DEB安装命令来安装的例子:
 
+
 
+
There are generally two ways to install RPM files manually. The first method is by using a file previously downloaded to your hard drive, and the other is to install the RPM from some sort of removable media such as a CD-ROM drive.
+
 
+
 
+
=== Using Downloaded Files ===
+
 
+
Download the RPMs (which usually have a file extension ending with .rpm) into a temporary directory, such as /tmp. The next step is to issue the rpm -Uvh command to install the package.
+
 
+
The -U qualifier is used for updating an RPM to the latest version, the -h qualifier gives a list of hash # characters during the installation and the -v qualifier prints verbose status messages while the command is run. Here is an example of a typical RPM installation command to install the MySQL server package:
+
 
+
[root@bigboy tmp]# rpm -Uvh mysql-server-3.23.58-9.i386.rpm
+
Preparing...        ####################### [100%]
+
  1:mysql-server  ####################### [100%]
+
[root@bigboy tmp]#
+
 
+
 
+
=== Using CD-ROMs ===
+
 
+
The underlying steps to install RPMs from CDs are similar to those used when installing from your hard disk. The main difference is that you have to access your CD-ROM drive by mounting it first to the mnt/cdrom directory. Your RPMs will then be located in the CD-ROM's Fedora/RPMs subdirectory. The procedure is as follows:
+
 
+
1) Insert the CD-ROM, check the files in the /mnt/cdrom/Fedora/RPMS directory and then install the RPM.
+
 
+
[root@bigboy tmp]# mount /mnt/cdrom
+
[root@bigboy tmp]# cd /mnt/cdrom/Fedora/RPMS
+
[root@bigboy RPMS]# ls filename*
+
filename.rpm
+
[root@bigboy RPMS]# rpm -Uvh filename.rpm
+
  Preparing...        ####################### [100%]
+
    1: filename      ####################### [100%]
+
  [root@bigboy RPMS]#
+
 
+
2) When finished, eject the CD-ROM
+
 
+
[root@bigboy RPMS]# cd /tmp
+
[root@bigboy tmp]# eject cdrom
+
[root@bigboy tmp]#
+
 
+
'''Note:''' You can use the rpm command's --aid switch to make it search the CD-ROM for any other RPM dependencies and install them automatically.
+
 
+
 
+
== How to Install Source RPMs ==
+
 
+
Sometimes the packages you want to install need to be compiled in order to match your kernel version. This requires you to use source RPM files:
+
 
+
* Download the source RPMs or locate them on your CD collection. They usually have a file extension ending with (.src.rpm)
+
* Run the following commands as root:
+
 
+
Compiling and installing source RPMs with Fedora can be done simply with the rpmbuild command
+
 
+
[root@bigboy tmp]# rpmbuild --rebuild filename.src.rpm
+
 
+
Here is an example in which we install the tacacs plus package.
+
 
+
[root@bigboy rpm]# rpmbuild --rebuild tac_plus-4.0.3-2.src.rpm
+
Installing tac_plus-4.0.3-2.src.rpm
+
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.61594
+
+ umask 022
+
+ cd /usr/src/redhat/BUILD
+
+ cd /usr/src/redhat/BUILD
+
+ rm -rf tac_plus-4.0.3
+
+ /usr/bin/gzip -dc /usr/src/redhat/SOURCES/tac_plus-4.0.3.tgz
+
+ tar -xvvf -
+
...
+
...
+
...
+
+ umask 022
+
+ cd /usr/src/redhat/BUILD
+
+ rm -rf tac_plus-4.0.3
+
+ exit 0
+
[root@bigboy rpm]#
+
 
+
The compiled RPM file can now be found in one of the architecture subdirectories under /usr/src/redhat/RPMS directory. For example, if you compiled an i386 architecture version of the RPM it will placed in the i386 subdirectory.
+
 
+
You will then have to install the compiled RPMs found in their respective subdirectories as you normally would.
+
 
+
 
+
== RPM Installation Errors ==
+
 
+
Sometimes the installation of RPM software doesn't go according to plan and you need to take corrective actions. This section shows you how to recover from some of the most common errors you'll encounter.
+
 
+
 
+
=== Failed Dependencies ===
+
 
+
Sometimes RPM installations will fail giving Failed dependencies errors which really mean that a prerequisite RPM needs to be installed. In the next example we're attempting to install the MySQL database server application, which fails because the mysql MySQL client RPM, on which it depends, needs to be installed beforehand:
+
 
+
[root@bigboy tmp]# rpm -Uvh mysql-server-3.23.58-9.i386.rpm
+
error: Failed dependencies:
+
        libmysqlclient.so.10 is needed by mysql-server-3.23.58-9
+
        mysql = 3.23.58 is needed by mysql-server-3.23.58-9
+
[root@bigboy tmp]#
+
 
+
Installing the MySQL client also fails because it requires the perl-DBD-MySQL package.
+
 
+
[root@bigboy tmp]# rpm -Uvh mysql-3.23.58-9.i386.rpm
+
error: Failed dependencies:
+
        perl-DBD-MySQL is needed by mysql-3.23.58-9
+
[root@bigboy tmp]# rpm -Uvh perl-DBD-MySQL-2.9003-4.i386.rpm
+
error: Failed dependencies:
+
        libmysqlclient.so.10 is needed by perl-DBD-MySQL-2.9003-4
+
[root@bigboy tmp]#
+
 
+
Strangely enough, the installation of the perl-DBD-MySQL package fails because it needs the mysql client package. To get around this problem you can run the rpm command with the --nodeps option to disable dependency checks. In the next example we install the MySQL client ignoring dependencies, followed by successful installation of perl-DBD-MySQL and mysql-server.
+
 
+
[root@bigboy tmp]# rpm -Uvh --nodeps mysql-3.23.58-9.i386.rpm
+
Preparing...        ####################### [100%]
+
    1:mysql          ####################### [100%]
+
[root@bigboy tmp]# rpm -Uvh perl-DBD-MySQL-2.9003-4.i386.rpm
+
Preparing...        ####################### [100%]
+
    1:perl-DBD-MySQL ####################### [100%]
+
[root@bigboy tmp]# rpm -Uvh mysql-server-3.23.58-9.i386.rpm
+
Preparing...        ####################### [100%]
+
    1:mysql-server  ####################### [100%]
+
[root@bigboy tmp]#
+
 
+
'''Note:''' If all the installation RPMs are located in the same directory, the rpm command can automatically install all the prerequisite RPMs using the --aid option. One of the advantages of using the yum facility is that you don't have to worry about this dependency process as much because the dependency RPMs are always downloaded and installed automatically also.
+
 
+
=== Signature Keys ===
+
 
+
Fedora digitally signs all its RPM files, so it's best to import their public encryption key beforehand so that the RPM installation program will be able to verify the validity of the RPM file.
+
 
+
This is usually done automatically in newer versions of Fedora, but will need to be done manually in legacy versions. The manual method uses the rpm command as seen in the next example, but locate the key files first as their locations can vary between Fedora distributions. It is a good idea to import both the RedHat and Fedora keys:
+
 
+
 
+
[root@bigboy tmp]# locate RPM-GPG-KEY
+
/usr/share/rhn/RPM-GPG-KEY
+
/usr/share/rhn/RPM-GPG-KEY-fedora
+
[root@bigboy tmp]# rpm --import /usr/share/rhn/RPM-GPG-KEY
+
[root@bigboy tmp]# rpm --import /usr/share/rhn/RPM-GPG-KEY-fedora
+
[root@bigboy tmp]#
+
 
+
If you don't install the keys you'll get a DSA signature warning that alerts you to the fact that the RPM file might be bogus:
+
 
+
[root@bigboy tmp]# rpm -Uvh dhcp-3.0pl2-6.16.i386.rpm
+
warning: dhcp-3.0pl2-6.16.i386.rpm: V3 DSA signature: NOKEY, key ID 4f2a6fd2
+
Preparing...          #################################### [100%]
+
    1:dhcp              #################################### [100%]
+
[root@bigboy tmp]#
+
 
+
It is always good to install the key files. If they are not there, the RPMs will install with only a warning message. If the RPM's digital signature doesn't match that in the key file, the rpm installation program also alerts you and fails to install the RPM package at all:
+
 
+
[root@bigboy tmp]# rpm -Uvh dhcp-3.0pl2-6.16.i386.rpm
+
error: dhcp-3.0pl2-6.16.i386.rpm: V3 DSA signature: BAD, key ID 4f2a6fd2
+
error: dhcp-3.0pl2-6.16.i386.rpm cannot be installed
+
[root@bigboy tmp]#
+
 
+
Signatures are therefore useful because they help protect you against tampered and otherwise corrupted RPMs being installed.
+
 
+
== How to List Installed RPMs ==
+
 
+
The rpm -qa command will list all the packages installed on your system
+
 
+
[root@bigboy tmp]# rpm -qa
+
perl-Storable-1.0.14-15
+
smpeg-gtv-0.4.4-9
+
e2fsprogs-1.27-9
+
libstdc++-3.2-7
+
audiofile-0.2.3-3
+
...
+
...
+
...
+
[root@bigboy tmp]#
+
 
+
You can also pipe the output of this command through the grep command if you are interested in only a specific package. In this example we are looking for all packages containing the string ssh in the name, regardless of case (-i means ignore case)
+
 
+
[root@bigboy tmp]# rpm -qa | grep -i ssh
+
openssh-server-3.4p1-2
+
openssh-clients-3.4p1-2
+
openssh-askpass-gnome-3.4p1-2
+
openssh-3.4p1-2
+
openssh-askpass-3.4p1-2
+
[root@bigboy tmp]#
+
 
+
'''Note:''' You could use the rpm -q package-name command to find an installed package because it is much faster than using grep and the -qa switch, but you have to have an exact package match. If you are not sure of the package name and its capitalization, the latter method is probably more suitable.
+
 
+
 
+
== Listing Files Associated with RPMs ==
+
 
+
Sometimes you'll find yourself installing software that terminates with an error requesting the presence of a particular file. In many cases the installation program doesn't state the RPM package in which the file can be found. It is therefore important to be able to determine the origin of certain files, by listing the contents for RPMs in which you suspect the files might reside.
+
+
 
+
=== Listing Files for Already Installed RPMs ===
+
 
+
This can be useful if you have to duplicate a working server that is already in a production environment. Sometimes the installation of an application fails on the new server due to the lack of a file that resides on the old one. In this case you need to know which RPM on the old server contains the file.
+
 
+
You can use the -ql qualifier to list all the files associated with an installed RPM. In this example we test to make sure that the NTP package is installed using the -q qualifier, and then we use the -ql qualifier to get the file listing.
+
 
+
[root@bigboy tmp]# rpm -q ntp
+
ntp-4.1.2-0.rc1.2
+
[root@bigboy tmp]# rpm -ql ntp
+
/etc/ntp
+
/etc/ntp.conf
+
/etc/ntp/drift
+
/etc/ntp/keys
+
...
+
...
+
...
+
/usr/share/doc/ntp-4.1.2/rdebug.htm
+
/usr/share/doc/ntp-4.1.2/refclock.htm
+
/usr/share/doc/ntp-4.1.2/release.htm
+
/usr/share/doc/ntp-4.1.2/tickadj.htm
+
[root@bigboy tmp]#
+
 
+
 
+
=== Listing Files in RPM Files ===
+
 
+
Sometimes you make a guess and download what you think is the RPM with the missing file. You can use the -qpl qualifier to list all the files in an RPM archive to make sure before installing it:
+
 
+
[root@bigboy updates]# rpm -qpl dhcp-3.0pl1-23.i386.rpm
+
/etc/rc.d/init.d/dhcpd
+
/etc/rc.d/init.d/dhcrelay
+
/etc/sysconfig/dhcpd
+
/etc/sysconfig/dhcrelay
+
...
+
...
+
...
+
/usr/share/man/man8/dhcrelay.8.gz
+
/var/lib/dhcp
+
/var/lib/dhcp/dhcpd.leases
+
[root@bigboy updates]#
+
 
+
 
+
=== Listing the RPM to Which a File Belongs ===
+
 
+
You might need to know the RPM that was used to install a particular file. This is useful when you have a suspicion about the function of a file but are not entirely sure. For example, the MySQL RPM uses the /etc/my.cnf file as its configuration file, not a file named /etc/mysql.conf as you'd normally expect. The following example confirms the origin of the /etc/my.cnf file.
+
 
+
[root@zippy tmp]# rpm -qf /etc/my.cnf
+
mysql-3.23.58-9
+
[root@zippy tmp]#
+
 
+
 
+
=== Uninstalling RPMs ===
+
 
+
The rpm -e command will erase an installed package. The package name given must match that listed in the rpm -qa command because the version of the package is important.
+
 
+
[root@bigboy tmp]# rpm -e package-name
+
 
+
 
+
=== Which RPMs Will Start Up At Boot Time? ===
+
 
+
The best way to view and configure which RPMs will start at boot time is by using the chkconfig command with the --list switch. A more detailed explanation will be provided in Chapter 7, "[[Quick HOWTO : Ch07 : The Linux Boot Process|The Linux Boot Process]]", which covers the Linux boot process.
+
 
+
== Automatic Updates with yum ==
+
 
+
The yum automatic RPM update program comes as a standard feature of Fedora Core. It has a number of valuable features:
+
 
+
* You can configure the URLs of download sites containing the RPM repositories you need. This provides the added advantage of you choosing the most reliable sites in your part of the globe.
+
* yum makes multiple attempts to download RPMs before failing.
+
* yum automatically figures out not only the RPMs packages that need updating, but also all the supporting RPMs. It then installs them all.
+
 
+
'''Note:''' Updating packages could cause programs written by you to stop functioning especially if they rely on the older version's features or syntax.
+
 
+
 
+
=== Configuring yum ===
+
 
+
The configuration parameters that affect all packages and all yum server URLs are stored in the [main] section of the /etc/yum.conf file. You generally don't need to edit this file, but it can be useful in listing packages that you don't want yum to update. In this example the kernel and perl packages are excluded.
+
 
+
#
+
# File: /etc/yum.conf
+
#
+
+
[main]
+
exclude=kernel perl
+
 
+
 
+
The configurations for each RPM repository are stored in the /etc/yum.repos.d directory in individual configuration files with the .repo file extension. This directory will be populated with files for your Linux distribution's most important repositories. You can also add your own custom files for repositories containing non-standard RPM packages. These files will have the following format:
+
 
+
[repositoryid]
+
name=Some name for this repository
+
baseurl=url://path/to/repository/
+
 
+
The [repositoryid] is an identifier that is unique to all files in the directory and can only be one word long and is often given a name that reflects the function of the repository. For example, you may have a fedora-updates.repo file that contains a [updates], and [updates-source] sections that refer to URLs for updates of regular RPMs and source RPMs.
+
You can create your own repository files using popular repository sites. The easiest way to determine the exact URLs to use as the baseurl parameter is to go to the http://fedora.redhat.com/download/mirrors.html Web site to get a listing of alternative download sites. Browse the listed sites to find the correct locations of the RPM files in the /updates or /fedora-version URL branches. Make sure that baseurl points to a URL with a /repodata sub-directory beneath it as this sub-directory contains files with instructions for yum to use in doing its updates. Be careful, this sub-directory can be located within the RPM directory or one level above them. Also remember to make the [repositoryid] in your .repo file unique to all other files.
+
 
+
'''Note:''' yum accepts the use of variables in the configuration file. The $releasever variable refers to the current version of Fedora Core running on your server and the $basearch variable maps to the base architecture of your server which is determined automatically. Here is an example of the use of these variables.
+
 
+
[repository-name]
+
name=Fedora Core $releasever - $basearch - Base
+
baseurl=http://url.com/fedora/core/$releasever/$basearch/os/
+
 
+
'''Note:''' It is probably best to select yum update sites that use HTTP instead of FTP. There are a number of reasons for this. FTP firewall rules are more difficult to implement than HTTP, outbound HTTP access to the Internet is often already allowed in offices, and web servers are less likely to have connection limits imposed on them, unlike FTP servers, which often have limits on the number of user logins.
+
Note: You can list multiple URLs in a baseurl statement like this and yum will try them all. If you use multiple baseurl statements in each section then yum may act strangely, frequently only selecting the last one in the list.
+
 
+
baseurl=url://server1/path/to/files/
+
        url://server2/path/to/files/
+
        url://server3/path/to/files/
+
+
'''Note:''' You can also place all your [repositoryid] sections in the yum.conf file. This was the methodology used in some older versions of yum.
+
 
+
'''Note:''' The yum utility can be configured to match the downloaded RPMs against checksum files to help protect against file corruption and malicious forgeries. This is set using the gpgcheck variable in the .repo files. Checks are done when the value is set to 1, when set to 0, they are disabled. Here is an example:
+
 
+
#
+
# File: example.repo
+
#
+
gpgcheck=1
+
gpgkey=http://URL/example.key
+
 
+
Repositories will sometimes provide you with the URL for their checksum files and it is a good idea to take advantage of them. This is a valuable feature.
+
 
+
=== How to Automate yum ===
+
 
+
Older versions of yum could be configured to run in the background as a daemon that was simple named yum that used a unified yum.conf file for all its configuration data. Newer versions use the yum-updatesd daemon instead. This uses the /etc/yum/yum-updatesd.conf configuration file which governs update frequency, the types of files to be downloaded and whether they should be automatically installed using the yum command.
+
 
+
To get yum started, select the commands that match your OS version:
+
 
+
1. Use the chkconfig command to get yum configured to start at boot:
+
 
+
[root@bigboy tmp]# chkconfig yum-updatesd on
+
+
[root@bigboy tmp]# chkconfig yum on
+
 
+
2. Use the service command to instruct the /etc/init.d yum script to start/stop yum after booting
+
 
+
[root@bigboy tmp]# service yum-updatesd start
+
[root@bigboy tmp]# service yum-updatesd stop
+
 
+
[root@bigboy tmp]# service yum start
+
[root@bigboy tmp]# service yum stop
+
 
+
'''Note:''' Updating packages could cause programs written by you to stop functioning especially if they rely on the older version's features or syntax. The yum daemon will do updates automatically; the yum-updatesd daemon won't do this unless the yum-updatesd.conf file has been updated as shown here:
+
 
+
#
+
# File: /etc/yum/yum-updatesd.conf
+
#
+
+
[main]
+
do_update = yes
+
 
+
=== Creating Your Own yum Server ===
+
 
+
An obvious advantage of using yum is that you can use it to update a yum server at your office with the same directory structure of the mirror download sites on the Fedora Web site. The full set of steps to do this is beyond the scope of this book, but there are some factors you should consider before doing this.
+
 
+
A small desktop PC with about five to six gigabytes of free disk space per distribution should be sufficient to start with for a dedicated small business yum server. Large RPMs are about twenty-five megabytes in size, and they are updated infrequently, so your network load should be minimal on average with an update once or twice a week per server.
+
In large server farms you may want to use a more robust system that can handle many more clients, but before doing so, get trend data for its network load to help your final decision. The configuration of the MRTG graphing tool is covered in Chapter 22, "[[Quick HOWTO : Ch22 : Monitoring Server Performance| Monitoring Server Performance]]".
+
 
+
When established, you can then configure all your Fedora servers to use this local yum server for all updates which will significantly reduce your Internet congestion and the associated bandwidth costs.
+
 
+
yum clients can access the yum server using either FTP or HTTP requests. If you need help in setting these up, Chapter 15, "[[Quick HOWTO : Ch15 : Linux FTP Server Setup|Linux FTP Server Setup]]", discusses Linux FTP servers and Chapter 20, "[[Quick HOWTO : Ch20 : The Apache Web Server|The Apache Web Server]]", covers the Apache Web server for HTTP requests.
+
 
+
'''Note:''' When setting up an HTTP based yum server, you'll need to enable the viewing of directory structures so that it will be easy for someone to use his or her Web browser to navigate down the directories to double check the location of the yum files.
+
 
+
=== How to Automate yum ===
+
 
+
As of Fedora Core 6 the <code>yum</code> daemon has been named <code>yum-updatesd</code>, whereas in the past it was just called <code>yum</code>. To get yum started, select the commands that match your OS version:
+
 
+
1) Use the chkconfig command to get yum configured to start at boot:
+
 
+
  [root@bigboy tmp]# chkconfig yum-updatesd on
+
+
  [root@bigboy tmp]# chkconfig yum on
+
+
2) Use the service command to instruct the <code>/etc/init.d yum</code> script to start/stop yum after booting
+
+
[root@bigboy tmp]# service yum-updatesd start
+
[root@bigboy tmp]# service yum-updatesd stop
+
+
[root@bigboy tmp]# service yum start
+
[root@bigboy tmp]# service yum stop
+
 
+
 
+
 
+
=== Keeping Your System current with Yum ===
+
 
+
 
+
You can make the installed RPM packages on your system up to date with the latest patches using the yum update command. When used without listing any packages afterwards, yum will attempt to update them all. The yum update package-name command updates only a particular RPM package.
+
 
+
It is always advisable to use yum after installing Linux to make sure the latest versions of software are installed for the sake of improved security and functionality. Here is an example of output of what to expect with yum updating your system.
+
 
+
[root@bigboy tmp]# yum update
+
Gathering header information file(s) from server(s)
+
Server: Fedora Core 2 - i386 - Base
+
Server: Fedora Core 2 - i386 - Released Updates
+
Finding updated packages
+
Downloading needed headers
+
Resolving dependencies
+
Dependencies resolved
+
I will do the following:
+
[install: kernel 2.4.22-1.2166.nptl.i686]
+
[update: samba-client 3.0.2-7.FC1.i386]
+
[update: binutils 2.14.90.0.6-4.i386]
+
...
+
...
+
...
+
Is this ok [y/N]: y
+
Getting samba-client-3.0.2-7.FC1.i386.rpm
+
samba-client-3.0.2-7.FC1. 100% |=========================| 128 kB    05:01
+
...
+
...
+
...
+
Running test transaction:
+
Test transaction complete, Success!
+
glibc-common 100 % done 1/127
+
glibc 100 % done 2/127
+
Stopping sshd:[  OK  ]
+
Starting sshd:[  OK  ]
+
bash 100 % done 3/127
+
mozilla-nspr 100 % done 4/127
+
sed 100 % done 5/127
+
...
+
...
+
...
+
Completing update for pango  - 65/127
+
Completing update for samba-client  - 66/127
+
Completing update for binutils  - 67/127
+
...
+
...
+
...
+
Completing update for XFree86-font-utils  - 127/127
+
Kernel Updated/Installed, checking for bootloader
+
Grub found - making this kernel the default
+
Installed:  kernel 2.4.22-1.2166.nptl.i686
+
Updated:  pango 1.2.5-4.i386 samba-client 3.0.2-7.FC1.i386 binutils 2.14.90.0.6-4.i386 XFree86-Mesa-libGLU 4.3.0-55.i386 initscripts
+
[root@bigboy tmp]#
+
 
+
'''Note:''' If you don't want to be prompted to install the files use the yum with the -y switch.
+
 
+
 
+
=== Example of a yum Package Installation ===
+
 
+
 
+
Here is a sample installation of an individual package using yum. In this case the RPM installed is the net-snmp-utils package:
+
 
+
 
+
[root@bigboy tmp]# yum -y install  net-snmp-utils
+
Repository updates-released already added, not adding again
+
Repository base already added, not adding again
+
Setting up Install Process
+
Setting up Repo:  base
+
repomd.xml          100% |=========================| 1.1 kB    00:00
+
Setting up Repo:  updates-released
+
repomd.xml          100% |=========================|  951 B    00:00
+
Reading repository metadata in from local files
+
base      : ############################################ 2622/2622
+
primary.xml.gz      100% |=========================|  88 kB    00:00
+
MD Read  : ################################################## 229/229
+
updates-re: ################################################## 229/229
+
Resolving Dependencies
+
--> Populating transaction set with selected packages. Please wait.
+
---> Package net-snmp-utils.i386 0:5.1.2-11 set to be installed
+
--> Running transaction check
+
 
+
Dependencies Resolved
+
Transaction Listing:
+
  Install: net-snmp-utils.i386 0:5.1.2-11
+
Downloading Packages:
+
net-snmp-utils-5.1.2-11.i 100% |===================| 6.2 MB    00:48
+
Running Transaction Test
+
Finished Transaction Test
+
Transaction Test Succeeded
+
Running Transaction
+
Installing: net-snmp-utils 100 % done 1/1
+
 
+
Installed: net-snmp-utils.i386 0:5.1.2-11
+
Complete!
+
[root@bigboy tmp]#
+
 
+
 
+
=== Remember The Following Yum Facts ===
+
 
+
* yum does its updates using TCP port 80 for http:// update URLs and uses passive FTP for ftp:// update URLs in /etc/yum.conf. This will have importance for your firewall rules.
+
* More details on configuring yum can be obtained by running the man yum.conf command.
+
* yum runs automatically each day. The cron file is located in /etc/cron.daily/.
+
* Don't limit yourself to the default yum.conf URLs because they can become overloaded with requests and make yum perform poorly.
+
 
+
=Installing Software From DEB Files=
+
 
+
Unlike the Redhat, Fedora and Centos versions of Linux that use RPM packages, the Debian and Ubuntu versions of Linux rely on packages in the DEB format. This section covers some of the most important topics required for you to master their use.
+
==How To Install DEBs Manually==
+
There are generally two ways to install DEB files manually. The first method is by using a file previously downloaded to your hard drive, and the other is to install the DEB from some sort of removable media such as a CD-ROM drive.
+
===Using Downloaded Files===
+
Download the DEBs (which usually have a file extension ending with .deb) into a temporary directory, such as /tmp. The next step is to issue the dpkg --install command to install the package. Here is an example of a typical DEB installation command to install the ndiswrapper utilities package:
+
  
 
  root@u-bigboy:~# dpkg --install ndiswrapper-utils_1.8-0ubuntu2_i386.deb  
 
  root@u-bigboy:~# dpkg --install ndiswrapper-utils_1.8-0ubuntu2_i386.deb  
第704行: 第235行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 
   
 
   
===Using CD-ROMs===
+
===用光盘===
Installing DEB files from CDROM is similar to that with Fedora / Redhat. The difference is that the CDROM device name is /media/cdrom. The following procedure installs the ndiswrapper DEB that had previously been copied to a disk.:
+
用光盘安装DEB文件和在Fedora和RedHat中的情况是类似的。区别在于光盘设备名称是/media/cdrom。下面的步骤将安装事先拷贝到光盘上的ndiswrapper DEB包:
  
1. Insert the CD-ROM, check the files in the /media/cdrom directory and then install the DEB.
+
1. 插入光盘,检查/media/cdrom路径下的文件,然后安装DEB。
  
 
  root@u-bigboy:/tmp# mount /media/cdrom -o unhide
 
  root@u-bigboy:/tmp# mount /media/cdrom -o unhide
第721行: 第252行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
2. When finished, eject the CD-ROM
+
2. 结束后,弹出光盘
  
 
  root@u-bigboy:/media/cdrom# cd /tmp
 
  root@u-bigboy:/media/cdrom# cd /tmp
第728行: 第259行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
  
'''Note:''' Unlike the Fedora CD / DVD sets, Ubuntu Linux is distributed on a single CD / DVD. The Ubuntu installation process downloads any additional packages it may need on demand from the Internet. It is for this reason that you may find it easier to install Ubuntu software using the APT utility which automatically download and install most of the packages you desire. The APT utility is covered in a following section.
+
'''注意:'''不像Fedora使用多张CD/DVD,Ubuntu是用一张CD/DVD盘发布的。Ubuntu安装进程从互联网上下载任何需要的软件包。因此,你可能发现使用APT工具要简单,它能够自动的下载安装大部分你要的软件包。下节会介绍APT工具。
==DEB Installation Errors==
+
 
Sometimes the installation of DEB software doesn't go according to plan and you need to take corrective actions. This section shows you how to recover from some of the most common errors you'll encounter.
+
==DEB安装错误==
===Failed Dependencies===
+
有时候DEB软件的安装并不会按照你的计划来,而你此时就需要有正确的措施。有一些最常见的错误你很有可能会遇到,本节将告诉你如何从中恢复过来。
As should be expected, packages often rely on the existence of other previously installed packages. This will sometimes result in dpkg installations failing with dependency problems errors which really mean that a prerequisite DEB needs to be installed. In the next example we're trying to install the mrtg-contrib package, but it needs the mrtg package to be installed first beforehand.
+
 
 +
===依赖失败(Failed Dependencies)===
 +
就像预想中的那样,软件包常常依赖其它一些已经安装的软件包。这可能会导致dpkg安装因依赖问题失败,而这就意味着有些必要的DEB要安装。在下一个例子中,我们要安装mrtg-contrib包,而他需要事先安装好mrtg包。
  
 
  root@u-bigboy:/tmp# dpkg --install mrtg-contrib_2.12.2-1_all.deb  
 
  root@u-bigboy:/tmp# dpkg --install mrtg-contrib_2.12.2-1_all.deb  
第747行: 第280行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
 
   
 
   
After installing the mrtg package, mrtg-contrib was installed correctly. You can automatically install prerequisite packages using the APT utility. This will be covered later in th echapter.
+
在安装了mrtg包之后,mrtg-contrib安装成功。用APT工具你可以自动的安装依赖包。这在本章稍后会讲述。
==How to List Installed DEBs==
+
==如何列出已安装的DEB==
The dpkg --list command will list all the packages installed on your system
+
dpkg --list命令会列出你系统中所有已安装的软件包。
  
 
  root@u-bigboy:~# dpkg --list
 
  root@u-bigboy:~# dpkg --list
第763行: 第296行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
The output will be in six columns. The fourth column lists the name of the package, the fifth states the package version, and the sixth and last provides a description.
+
命令的输出有6列:第4列是软件包的名称,第五列是包的版本,而最后的第6列是描述。
  
The first three columns are each only a single character wide and provide very specific information about the package as outlined in Table 6-3.
+
前面三列每个都是单字符宽,提供了包的详细信息,如表6-3:
  
===Table 6-3 Column Formatting for the dpkg command===
+
===表6-3 列格式的dpkg命令===
  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
|-
 
|-
! style="background:#008000;color:white" | Desired State
+
! style="background:#008000;color:white" | 期望状态
 
(Col. 1)
 
(Col. 1)
! style="background:#008000;color:white" | Current State
+
! style="background:#008000;color:white" | 当前状态
 
(Col. 2)
 
(Col. 2)
! style="background:#008000;color:white" | Error State
+
! style="background:#008000;color:white" | 错误状态
 
(Col. 3)
 
(Col. 3)
! style="background:#008000;color:white" | Description
+
! style="background:#008000;color:white" | 描述
 
|-
 
|-
| align="center"|u || || ||'''Unknown:''' The package has never been installed
+
| align="center"|u || || ||'''未知(Unknown):''' 此包未安装
 
|-
 
|-
| align="center"|i || || ||'''Installed:''' A privileged user has requested the installation of the package
+
| align="center"|i || || ||'''已安装(Installed):''' 特权用户已请求安装此包
 
|-
 
|-
| align="center"|r || || ||'''Remove:''' A privileged user has requested the removal of the package. Configuration files for the package most likely remain.
+
| align="center"|r || || ||'''移除(Remove):''' 特权用户已经请求移除此包,此包的配置文件很可能存在
 
|-
 
|-
| align="center"|p || || ||'''Purge:''' A previously installed package has been removed. Configuration files for the package have probably been removed.
+
| align="center"|p || || ||'''清除(Purge):''' 先前安装的包已被移除,此包的配置文件也许亦被移除
 
|-
 
|-
| align="center"|h || || ||'''Hold:''' A privileged user has requested that the package remain at its current version with no automatic upgrades.
+
| align="center"|h || || ||'''保持(Hold):''' 特权用户已请求此包保持当前版本不自动升级
 
|-
 
|-
| || align="center"|n|| ||'''Not Installed:''' The package is not installed
+
| || align="center"|n|| ||'''未安装(Not Installed):''' 此包未安装
 
|-
 
|-
| || align="center"|i|| ||'''Installed:''' The package is installed
+
| || align="center"|i|| ||'''已安装(Installed):''' 此包已安装
 
|-
 
|-
| || align="center"|c|| ||'''Configuration Files Exist:''' Package was installed, but the configuration files exist.
+
| || align="center"|c|| ||'''配置文件存在(Configuration Files Exist):''' 包被安装,而配置文件已经存在
 
|-
 
|-
| || align="center"|u|| ||'''Unpacked:''' Files have been unpacked, but not installed
+
| || align="center"|u|| ||'''解包(Unpacked):''' 文件已被解包,但是未安装
 
|-
 
|-
| || align="center"|f|| ||'''Failed:''' Configuration of the package has failed.
+
| || align="center"|f|| ||'''失败(Failed):''' 此包配置失败
 
|-
 
|-
| || align="center"|h|| ||'''Halt:''' The package installation failed to complete
+
| || align="center"|h|| ||'''停止(Halt):''' 此包安装失败,中途停止
 
|-
 
|-
| || || align="center"|h||'''Enforced Hold:''' Package upgrade is on hold because another dependent package with a user defined hold requires this package to remain not upgraded.
+
| || || align="center"|h||'''强迫保持(Enforced Hold):''' 因为依赖包被定义为保持,此包的升级被搁置
 
|-
 
|-
| || || align="center"|r||'''Reinstallation:''' The package is broken and requires a reinstallation.
+
| || || align="center"|r||'''重新安装(Reinstallation):''' 此包破损需要重新安装
 
|-
 
|-
| || || align="center"|x||The package is both broken and on enforced hold.
+
| || || align="center"|x||此包破损且为强制保持
 
|-
 
|-
 
|}
 
|}
  
 
+
你可以用--list选项来指定你感兴趣的包,并显示它们。下面我们用这种方法,单独列出了openssh-server软件包。
You can specify the desired package in which you are interested after the --list option to get a listing specific to that package. Here we see a single listing for the openssh-server package using this method.
+
  
 
  root@u-bigboy:~# dpkg --list openssh-server
 
  root@u-bigboy:~# dpkg --list openssh-server
第821行: 第353行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
You can also pipe the output of this command through the grep command if you are interested in only a specific package. In this example we are looking for all packages containing the string dhcp in the name.
+
如果你只对一个确切的包感兴趣,你可以将输出用管道重定向到grep命令。在下面的例子中,我们要找到所有名字中包含“dhcp”字符串的软件包。
  
 
  root@u-bigboy:~# dpkg --list | grep dhcp
 
  root@u-bigboy:~# dpkg --list | grep dhcp
第828行: 第360行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
==Listing Files Associated with DEBs==
+
==列出与DEB相关的文件==
Sometimes you'll find yourself installing software that terminates with an error requesting the presence of a particular file. In many cases the installation program doesn't state the DEB package in which the file can be found. It is therefore important to be able to determine the origin of certain files, by listing the contents for DEBs in which you suspect the files might reside.
+
有时候,你安装软件的过程会因一个错误而中止,这个错误请求某一个文件要存在。很多情况下,安装程序并不说明在哪个包中可以找到这个文件。因此能够确定某些文件的来源很重要,而这可以通过列出你怀疑可能包含该文件的软件包的内容来实现。
===Listing Files for Previously Installed DEBs===
+
 
As stated previously, listing the files found in a package can be very useful. With dpkg, the --listiles option can provide this information easily. Here we list the files present in the openssh-server package.
+
===列出已安装软件包的文件===
 +
如前所述,列出软件包中的文件很重要。用dpkg,--listfiles选项可以轻松提供这一信息。下面我们列出openssh-server软件包中的文件。
  
 
  root@u-bigboy:~# dpkg --listfiles openssh-server
 
  root@u-bigboy:~# dpkg --listfiles openssh-server
第842行: 第375行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
===Listing Files in DEB Files===
+
===列出DEB文件中的文件===
Download sites often have packages with different functions, but similar names. It is good to be able to list the contents of a DEB package to verify you have the correct one. This can be done with the --contents option for dpkg as can be seen in this example.
+
下载网站上通常有一些包功能不同而名字相似。通过列出DEB包的内容来确认你的包是你想要的那个,是很好的方式。这可以通过dpkg的--contents选项来实现,如在这个例子中所见。
  
 
  root@u-bigboy:/tmp# dpkg --contents openssh-server_4.2p1-7ubuntu3_i386.deb
 
  root@u-bigboy:/tmp# dpkg --contents openssh-server_4.2p1-7ubuntu3_i386.deb
第861行: 第394行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
 
   
 
   
===Listing the DEB Package to Which a File Belongs===
+
===列出文件所属的软件包===
Searching for the ownership of a particular file is also simple when using the --search option with dpkg. In this example, we see that the /etc/syslog.conf file is a part of the sysklogd package.
+
搜索特定文件的所属包也可以通过dpkg的--search选项轻易实现。下面这个例子中,我们看到/etc/syslog.conf是sysklogd软件包的一部分。
  
 
  root@u-bigboy:~# dpkg --search /etc/syslog.conf
 
  root@u-bigboy:~# dpkg --search /etc/syslog.conf
第868行: 第401行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 
   
 
   
==Uninstalling DEBs==
+
==卸载DEB==
The dpkg --remove command will erase an installed package as seen in this example.
+
dpkg --remove命令可以清除一个安装了的包,如下例:
  
 
  root@u-bigboy:~# dpkg --remove ndiswrapper-utils
 
  root@u-bigboy:~# dpkg --remove ndiswrapper-utils
第876行: 第409行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 
   
 
   
==Which DEBs Will Start Up At Boot Time?==
+
==哪些包在启动时开始运行?==
You can view and configure which DEBs will start at boot time is by using the <code>update-rc.d</code> command. A more detailed explanation will be provided in Chapter 7, [[Quick HOWTO : Ch07 : The Linux Boot Process|"The Linux Boot Process"]].
+
<code>update-rc.d</code>命令,你可以查看和配置哪些包在启动时开始运行。第7章[[Quick HOWTO : Ch07 : The Linux Boot Process/zh|"The Linux Boot Process"]]有对此更加详细的介绍。
  
==Automatic DEB Updates with apt-get==
+
==用apt-get自动更新DEB==
Like Fedora, Debian / Ubuntu Linux has its own package update application that will automatically retrieve packages from a network based repository. It is called the Advanced Package Tool (APT) and it is the most commonly used command is apt-get which we'll cover in more detail later
+
就像Fedora,Debian/Ubuntu Linux有它自己的包更新程序,此程序会自动地从基于仓库的网络中获取软件包。它叫做高级包工具(APT)。它最常用的命令是apt-get,稍后会更详细讲述此命令。
===Configuring APT===
+
===配置APT===
APT uses the /etc/apt/sources.list file to instruct your server as to where to find the required packages on your network. The default file locations in this file refer to a few trusted APT download websites on the Internet.
+
APT使用/etc/apt/sources.list文件来说明你网络中的服务器,从中你可以找到你需要的包。此文件中的默认文件地址,可以参考一些可信的APT下载网站。
  
It is important to periodically resynchronize the APT package index files from the sources listed in the /etc/apt/sources.list file. This updates your system with listings of the most current package versions. This can be done with the apt-get update command as seen here:
+
/etc/apt/sources.list文件中列举的软件源中,周期性地同步APT包索引文件,是很重要的事情。它用包的最新版本列表来更新你的系统。这可以通过apt-get update命令实现,如下:
 
  root@u-bigboy:/tmp# apt-get update
 
  root@u-bigboy:/tmp# apt-get update
 
  Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B]         
 
  Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B]         
第896行: 第429行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
  
'''Note:''' If you install Ubuntu without Internet access, only a barebones set of packages will be installed and the URL entries in the /etc/apt/sources.list file will be commented out, but the required packages will be flagged for eventual installation in the dpkg database. When you get Internet access, uncomment the URL entries and upgrade your installation with the apt-get command which will update your system with the full complement of required packages downloaded from the Web.
+
'''注意:'''如果你安装Ubuntu时无法接入互联网,你只能够安装最基本的软件包,/etc/apt/sources.list文件中的URL条目也会被注释掉。但是要安装的软件包会被标记,直到最后从dpkg数据库中安装它们。当你可以接入互联网时,取消对URL条目的注释,然后用apt-get命令来安装升级。这将从网上下载所有需要的包来升级你的系统。
  
You can also create an APT server on your own network if you don't want all your Debian / Ubuntu servers to have Internet access. You'll have to update your sources.list file accordingly, but the full configuration steps are beyond the scope of this book.
+
如果你不想你所有的Debian/Ubuntu服务器都接入互联网,你也可以在你的网络中搭建一个APT服务器。你就必须相应地更新你的sources.list文件,但是对此的完整配置步骤超出了本书范围。
  
===Keeping Your System current with APT===
+
===用APT保持系统最新===
The apt-get utility can be used to simultaneously upgrade all the packages on your system with the upgrade option. When used without listing any packages afterwards, apt-get will attempt to update them all. The apt-get upgrade package-name command updates only a particular DEB package.
+
用upgrade选项,apt-get工具可以用来同时升级你系统中的所有软件包。若在其后没有列出任何软件包时就使用apt-get,它会试图更新所有包。“apt-get upgrage 包名”命令只更新指定DEB包。
  
It is always advisable to use apt-get after installing Linux to make sure the latest versions of software are installed for the sake of improved security and functionality. Here is an example of output of what to expect; the -y flag causes apt-get to assume "yes" as the answer to all prompts and allows it to run non-interactively:
+
在安装Linux后,因为要提升安全性和功能,使用apt-get来保证已安装了最新的软件通常是明智的做法。下面的例子显示了可能的输出(Here is an example of output of what to expect),-y标记会使apt-get在所有的询问中采取确认(“yes”),从而让其没有交互地径直运行下去:
  
 
  root@u-bigboy:/tmp# apt-get -y upgrade
 
  root@u-bigboy:/tmp# apt-get -y upgrade
第921行: 第454行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
  
===Example of an apt-get Package Installation===
+
===用apt-get安装包的例子===
Here is a sample installation of an individual package using yum. In this case the RPM installed is the apache Web server package:
+
下面是一个用apt-get安装软件包的例子,其中安装的包是apache网络服务器软件包。
  
 
  [root@ root@u-bigboy:/tmp# apt-get -y install apache
 
  [root@ root@u-bigboy:/tmp# apt-get -y install apache
第948行: 第481行:
 
  root@u-bigboy:/tmp#
 
  root@u-bigboy:/tmp#
  
===Remember The Following APT Facts===
+
===记住下面APT的事实===
* The APT utility's sources.list file primarily lists URLs using TCP port 80 (http://)  for its updates This will have importance for your firewall rules.
+
* APT工具的source.list文件主要列出使用TCP 80端口的URL(http:// ),来为APT的更新服务。这对你的防火墙规则很重要。
* More details on configuring yum can be obtained by running the man sources.list and the man apt-get commands.
+
* 运行“man sources.list”和“man apt-get”命令可以获取关于配置yum的更详细信息。
  
= Installing Software Using tar Files =
+
= 用tar文件安装软件=
  
Another popular software installation file format is the tar file, which can frequently be obtained from the Web sites of software developers, and online software libraries such as www.sourceforge.net.
+
tar格式的文件是另外一种流行的软件安装文件。它们通常可以从软件开发者的主页或者如http://www.sourceforge.net 这样的在线软件库下载。
  
The Linux tar command is used to archive files and typically have a .tar file extension in the file name. These files are also frequently compressed in the gzip format, and when they do, their file extensions will end with .tar.gz or .tgz. The commands to extract the data from either type are similar. When a tar file is uncompressed, the command to extract the data is tar -xvf filename.tar. When the archive is compressed, the command to use is tar -xzvf filename.tar.gz.
+
Linux里的tar命令用于档案文件,而且此文件通常有一个“.tar”文件后缀名。这些文件常常被压缩成gzip格式,而且在这种情况下,它们的后缀名将会是“.tar.gz”或者“.tgz”。从以上两种文件中提取数据的命令是类似的。当解压一个tar文件时,提取数据的命令是“tar -xvf 文件名.tar”。当解压档案文件时,要用的命令是“tar -xzvf 文件名.tar.gz”。
  
The tar file installation process usually requires you first to uncompress and extract the contents of the archive in a local subdirectory, which frequently has the same name as the tar file. The subdirectory will usually contain a file called README or INSTALL, which outlines all the customized steps to install the software.
+
tar文件安装方法中,你首先要解压档案文件,并提取其中的内容放置在一个本地子目录中,这个子目录的名称通常和tar文件的名称是一样的。通常这个子目录里会有一个叫做README(读我)或者INSTALL(安装)的文件,其概述了安装软件所需的所有步骤。
  
Here are the initial steps to take to install tar-based software:
+
下面是安装基于tar的软件的最初几个步骤:
  
1) Issue the tar command to extract the files.
+
1)输入从指定文件中提取数据的tar命令。
  
 
  [root@bigboy tmp]# tar -xvzf linux-software-1.3.1.tar.gz
 
  [root@bigboy tmp]# tar -xvzf linux-software-1.3.1.tar.gz
第979行: 第512行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
2) Use the cd command to enter the subdirectory and follow the directions listed in the INSTALL and README files:
+
2)使用cd命令进入生成的子目录,并按照README和INSTALL文件中所列的指示来做:
  
 
  [root@bigboy tmp]# cd linux-software-1.3.1
 
  [root@bigboy tmp]# cd linux-software-1.3.1
第990行: 第523行:
 
  [root@bigboy linux-software-1.3.1]#
 
  [root@bigboy linux-software-1.3.1]#
  
Software installation with tar files can be frustrating, frequently requiring the installation of other supporting tar files, each with its own customized installation commands. RPMs, with the single standardized command format, are usually easier to use and may be the better method to use for newer Linux users.
+
用tar文件安装软件,常常需要安装别的支持tar文件,而且每一个有各自特定的安装命令,这会让人很沮丧。与此相反,RPM或DEB用一个标准的命令格式就可以安装,而且用起来也很简单,这对Linux新手来说可能是更好的方法。
  
=Installing Perl Modules=
+
=安装Perl模块=
  
Even if you don't know how to program in Perl, you may find yourself having to install Perl modules to get some of your software packages to work.
+
即使你不知道如何用Perl编程,你有时也不得不安装Perl模块来让你的软件包能够工作。
  
Modules can be installed manually by downloading the TAR files from www.cpan.org, the primary Perl module site. The disadvantage is that this method doesn't automatically install any prerequisite modules you may need. Another disadvantage, though small is that the perl module names usually have a double colon (::) in their names, but the installation TAR file in which this module resides won't have the colons in its name. For example version 1.74 of the <code>Mail::Tools</code> module has the file name <code>MailTools-1.74.tar.gz</code>.
+
可以从主要的Perl模块网站http://www.cpan.org 下载TAR文件然后手动安装Perl模块。这种方法的缺点是不能够自动安装需要的依赖包。另外的一个缺点(尽管比较小)是,Perl模块名称里通常有一个双冒号(::),但是包含此模块的TAR安装文件的名称里没有双冒号。比如1.74版的<code>Mail::Tools</code>模块的名称为<code>MailTools-1.74.tar.gz</code>
  
Modules can also be installed automatically using the <code>perl</code> command. We will cover both methods in this section.
+
也可以使用<code>perl</code>命令来自动安装Perl模块。本节我们会讲解这两种方法。
  
==Manual Installation of Perl Modules==
+
==Perl模块的手动安装==
  
Most of the commonly used Perl modules can be downloaded from the CPAN website. The installation steps are straightforward.
+
大部分常用的Perl模块都可以从CPAN网站下载。其安装步骤也简单易懂。
  
1. Browse the CPAN website, identify the module package you need and then download it using a utility such as wget.
+
1. 浏览CPAN网站,找到你需要的模块包,然后用类似wget的工具下载之。
  
 
  [root@bigboy tmp]# wget http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
 
  [root@bigboy tmp]# wget http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
第1,020行: 第553行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
2. Extract the file from the package with the tar command.
+
2. 用tar命令从模块包中提取文件。
  
 
  [root@bigboy tmp]# tar -xzvf MailTools-1.74.tar.gz  
 
  [root@bigboy tmp]# tar -xzvf MailTools-1.74.tar.gz  
第1,032行: 第565行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
3. Enter the newly created directory with the same name as the TAR file, and install the module with the following commands.
+
3. 进入新建的和TAR文件名称相同的目录,然后使用如下命令来安装此模块。
 
* perl Makefile.PL
 
* perl Makefile.PL
 
* make
 
* make
第1,063行: 第596行:
 
  [root@bigboy MailTools-1.74]#  
 
  [root@bigboy MailTools-1.74]#  
  
Your Perl module installation should now be complete.
+
你的Perl模块的安装现在应该就完成了。
  
'''Note:''' The output of the perl Makefile.PL command will tell you whether there are any other required modules. You can either install them all manually, running the risk of having to install more prerequisite modules for these prerequisite modules, or you can use automated updates which will be covered next.
+
'''注意:'''命令“perl Makefile.PL”的输出会告诉你,是否需要其余的一些模块。你可以全部都手动安装它们,同时冒着必须为这些依赖模块安装更多依赖模块的风险;或者你也可以用自动更新来安装,下面来讲解其具体事项。
  
==Automatic Installation of Perl Modules==
+
==Perl模块的自动安装==
  
Modules can be installed automatically using the <code>perl</code> utility but you must first install the prerequisite <code>ncftp</code> package to download the packages from <code>CPAN</code>.
+
虽然用<code>perl</code>工具可以自动安装模块,但是在此之前你必须要安装其依赖<code>ncftp</code>包,来从<code>CPAN</code>下载模块包。
  
 
  [root@bigboy tmp]# yum -y install ncftp
 
  [root@bigboy tmp]# yum -y install ncftp
  
After the package installed you can use the following <code>perl</code> command to enter the <code>CPAN</code> utility.
+
安装完这个模块包之后,你就可以使用如下的<code>perl</code>命令来进入<code>CPAN</code>工具。
  
 
  perl -MCPAN -e shell
 
  perl -MCPAN -e shell
  
The first time it is run, Perl will prompt you for a number of configuration options. In most cases the defaults will be sufficient. After the initial setup is complete you will have a cpan> command prompt
+
在其第一次运行时,Perl会提示你一些配置选项。大部分情况下使用默认配置就行了。在最初的安装完成后,你就有一个“cpan>”命令提示
  
 
  cpan>
 
  cpan>
  
Installation of modules can then be done with the install command followed by the name of the module. In this example we install the <code>Mail::Audit</code> module using the CPAN utility.
+
然后使用后接模块名的安装命令,就可以完成模块的安装了。在下面的例子中,我们用CPAN工具来安装<code>Mail::Audit</code>模块。
  
 
  [root@bigboy tmp]# perl -MCPAN -e shell
 
  [root@bigboy tmp]# perl -MCPAN -e shell
第1,107行: 第640行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
The exit command allows you to return to the Linux command prompt and your Perl module should be fully installed.
+
你的Perl模块完全安装完成后,退出命令能让你退出到Linux命令提示界面。
  
= Conclusion =
+
= 总结 =
  
This is just the beginning. If the software you install is intended to make your Linux machine permanently run an application such as a Web server, mail server, or any other type of server you have to know how to get the software activated when the system reboots. This is covered in Chapter 7, "[[Quick HOWTO : Ch07 : The Linux Boot Process|The Linux Boot Process]]". Subsequent chapters cover the use, configuration, testing, and troubleshooting of many of the most popular Linux server applications used today.
+
这仅仅只是个开始。如果你打算使你安装的软件让你的Linux计算机永久的运行一些程序,比如作为Web服务器、邮件服务器或者任何其它的服务器,你就必须知道如何在你的系统重新启动时就激活软件使其运行。这将会在第七章——"[[Quick HOWTO : Ch07 : The Linux Boot Process/zh|The Linux Boot Process(Linux引导过程)]]"中讲述。随后的章节将描述许多当前最流行的Linux服务器应用程序的使用、配置、测试和故障诊断方法。
 +
[[Category:Quick_HOWTO]]

2010年7月18日 (日) 15:44的最新版本

简介

当你第一次在你的Linux服务器上安装操作系统的时候,你常常需要安装一些你认为不需要的额外的软件。这可能是因为新的业务需要更多的软件包,或者是因为要安装新的管理工具来简化你的工作。

当Linux开发人员制作它们的软件的时候,它们总是将所有的可执行文件和数据文件捆绑在一起,从而形成一个叫做“软件包”的文件。包文件有许多种不同的格式,文件里有不同的控制文件。控制文件决定了软件包中其余文件应被放置的位置、拥有的权限以及整个软件包想要正常工作所依赖的软件包。这些信息中的一部分可能也储存你计算机中的一个数据库中,包管理软件可以使用它们来安装软件从而来加强自己的管理功能。

Redhat、Centos 和Fedora下的软件主要是用RedHat Package Manager (RPM) 文件。RPM软件包通常被用于在还没有定制内核或者管理程序的系统中安装软件。在部门服务器中这种情况经常发生。当因为效率或功能问题,来定制内核以增减对特定设备或特性的支持时,会使用源RPM。安装源RPM这一过程包括重新编译源代码,以使之适应定制内核的需求。这也可以方便制作包的软件开发者,现在他只需要制作一个包就可以支持不同类型的定制内核。不同的包都使用标准命令来安装其中的软件,这使得RPM包相对来说容易使用。

Debian和Ubuntu这两个Linux发行版使用Debian格式的软件包。此软件包的文件名是以“.deb”结尾的。也因为如此,我们通常称它们为DEB文件。

想要使用universal认证的文件格式从而使其产品在所有的Linux发行版中通用的程序员,也需要将他们的作品制作成TAR包。TAR包一般比RPM包难用,因为包中的文件可能需要也可能不需要编译,而且不同的包安装软件的命令也可能不同。TAR包中通常会有使用说明书来指导安装。

Linux程序员经常使用Perl语言写程序。Perl需要一些特定的库或“模块”才能正常工作,而许多Linux发布版只安装了最常用的模块。有时候在安装你的软件包之前,首先要先安装额外的Perl模块。知道如何安装Perl模块是Linux系统管理员技能的一个重要的组成部分。

本章致力于RPM和DEB格式,它们使用于大部分的安装文件中。TAR包和Perl模块很少使用,但是它们仍是重要的软件安装工具,它们将在最后面的一个小节有所交代。

何处获得常用软件包

软件包有三种常用来源:发行光盘;通过浏览器、FTP客户端或者wget工具手动下载;自动下载。每种方法在这里都有所介绍,但是更加详细的将会在后续章节中介绍。

安装光盘中的软件包

用发行光盘安装总是比从远程网站下载来安装要容易。但是时间长了,发行光盘就不是最新版的了。稍后,我们将更加详细的讨论这种方法。

手动下载软件包

获取软件包最常见的两种方法是通过FTP或浏览器手动下载。表6-1列举了一些常用的下载站点。记住,RPM的版本和你机器上运行的Linux的发行版和版本要匹配。

表6-1包常用下载网站

发行版 地址
Redhat http://www.redhat.com/

http://www.rpmfind.net/

Fedora ftp://download.fedora.redhat.com/pub/fedora/linux/core/

http://download.fedora.redhat.com/pub/fedora/linux/core/ http://www.rpmfind.net/

Debian http://packages.debian.org
Ubuntu http://packages.ubuntu.com

注意: 如果使用Fedora,你也可以从download.fedora.redhat.com下载软件包。在/pub/fedora/linux/core/路径中搜索,然后下移路径树。如果你是第一次使用FTP,别担心,稍后会有所介绍。

自动下载软件包

手动下载的缺点是软件包通常不能安装,除非它的依赖软件包已经事先装好了。这可能会导致要下载并安装很多软件包,而这会很乏味。

所有主要的Linux发行版都有自动下载更新的工具软件。比如,Fedora用yum而Ubuntu和Debian用apt。它们在接下来的章节都有更详细的介绍。

如何下载软件

下载软件是Linux系统管理员最经常要做的事情。这通常非常简单。这节将介绍最常用的几种方法。

用基于web的FTP获取软件

有很多网站都提供软件的链接,你可以通过它们下载软件。获取软件的这种方法通常是相同的:

  • 浏览网站,直到你找到要的软件包的链接。
  • 点击想要的软件包的链接。
  • 将那个文件保存在你的硬盘上。

有的浏览器,比如Firefox,会自动地将文件下载到你的桌面上,那桌面在哪里呢?在Linux里,桌面通常是一个在你的home或~目录下的一个叫Desktop(桌面)的子目录。在这里我们可以看到,在根用户的桌面上已经有一个下载下来的RPM文件。

 [root@bigboy tmp]# cd ~/Desktop/
 [root@bigboy Desktop]# ls
 ElectricFence-2.2.2-20.2.i386.rpm
 [root@bigboy Desktop]# pwd
 /root/Desktop
 [root@bigboy Desktop]#

用命令行匿名FTP获取软件

上面介绍的基于web的方法显然是使用匿名文件传输协议(FTP)。匿名FTP使你使用匿名用户名或更短的用户名ftp和符合你e-mail地址的密码,就可以登录FTP服务器并下载文件。任何人都可以通过这种方法获取数据。我们可以用一个用匿名FTP从download.fedora.redhat.com下载SSH软件包的例子来说明:

1)首先我们在命令行中向download.fedora.redhat.com发出FTP命令。

[root@bigboy tmp]# ftp download.fedora.redhat.com
Trying 66.187.232.35...
Connected to download.fedora.redhat.com (66.187.232.35).
220 Fedora FTP server ready. All transfers are logged.
Name (download.fedora.redhat.com:root): anonymous
331 Please specify the password.
Password:
230 Login successful. Have fun.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (66,187,232,35,57,155)
150 Here comes the directory listing.
drwxr-xr-x    3 ftp      ftp          4096 Oct 29 15:59 pub
226 Directory send OK.
ftp>

2)登录成功后,我们可以用help命令来查看我们可以做的事情。

ftp> help
Commands may be abbreviated.  Commands are:
(命令可能是缩写形式,有如下命令:)
!               cr              mdir            proxy           send
$               delete          mget            sendport        site
account         debug           mkdir           put             size
append          dir             mls             pwd             status
ascii           disconnect      mode            quit            struct
bell            form            modtime         quote           system
binary          get             mput            recv            sunique
bye             glob            newer           reget           tenex
case            hash            nmap            rstatus         trace
ccc             help            nlist           rhelp           type
cd              idle            ntrans          rename          user
cdup            image           open            reset           umask
chmod           lcd             passive         restart         verbose
clear           ls              private         rmdir           ?
close           macdef          prompt          runique
cprotect        mdelete         protect         safe
ftp>

表6-2列举了一些常用命令:


表6-2 FTP命令

命令 描述
binary 在二进制模式下拷贝文件
cd 改变FTP服务器上的目录
dir 列出当前远程目录里的文件的名称
exit 退出
get 从FTP服务器获取文件
lcd 改变本地计算机上的目录
ls 同dir
mget 同get,但是你可以使用如“*”的通配符
mput 同put,但是你可以使用如“*”的通配符
passive 使文件传输为被动模式
put 将本地计算机上的文件上传到FTP服务器
pwd 获取本地计算机的目录名

3)通过之前对网站上网页的浏览,我们可以知道Fedora Core 2 RPM包在pub/fedora/linux/core/2/i386/os/Fedora/RPMS/目录下。我们将使用cd命令将我们的目录改变到那里去。然后我们可以使用ls命令来获取那个目录下的文件的列表。

ftp> cd pub/fedora/linux/core/2/i386/os/Fedora/RPMS/
250 Directory successfully changed.
ftp> ls open*
227 Entering Passive Mode (66,187,232,35,58,3)
150 Here comes the directory listing.
...
...
-rw-r--r--   ... ... 184281 Oct 28 23:29 openssh-3.6.1p2-34.i386.rpm
...
...
226 Directory send OK.
ftp>

4)接下来,我们下载我们需要的文件并将其放置于本地的/usr/rpm目录下。hash命令会在下载时,在屏幕上打印井号“#”。

ftp> hash
Hash mark printing on (1024 bytes/hash mark).
ftp> lcd /usr/rpm
Local directory now /usr/rpm
ftp> get openssh-3.6.1p2-34.i386.rpm
 local: openssh-3.6.1p2-34.i386.rpm remote: openssh-3.6.1p2-34.i386.rpm
 227 Entering Passive Mode (66,187,232,35,58,25)
 150 Opening BINARY mode data connection for openssh-3.6.1p2-34.i386.rpm (184281 bytes).
 ###################################################################################################################################################################################
 226 File send OK.
 184281 bytes received in 3.41 secs (53 Kbytes/sec)
 ftp>

注意: 你也可以使用mget命令,从而在下载RPM时使用通配符。计算机会提示你每个符合的RPM文件名。在下个例子中,我通过键入n来中断这个下载。

ftp> mget openssh-3.6*
mget openssh-3.6.1p2-34.i386.rpm? n
ftp>

5)最后我们用exit命令退出FTP

ftp> exit
221 Goodbye.
root@bigboy tmp]#

用wget获取软件

当你已经知道RPM的URL地址时,你可以使用wget很快地下载该文件。如果你在别机器上通过浏览器登录到了Linux系统中,这种方法尤为方便。你可以浏览下载网站来找到你要的RPM,右键点击其链接然后选择复制快捷方式(Windows)或者复制链接位置(Linux)。这一步完成后,你然后可以选择你的SSH/telnet/Linux终端登录窗口然后键入wget URL命令。这里有一个从Fedora下载DHCP更新的例子。

[root@bigboy tmp]# wget http://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm
--17:38:36--  ftp://linux.stanford.edu/pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS/dhcp-3.0pl2-6.16.i386.rpm
           => `dhcp-3.0pl2-6.16.i386.rpm.5'
Resolving linux.stanford.edu... done.
Connecting to linux.stanford.edu[171.66.2.18]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD /pub/mirrors/fedora/linux/core/2/i386/os/Fedora/RPMS ... done.
==> PASV ... done.    ==> RETR dhcp-3.0pl2-6.16.i386.rpm ... done.
Length: 529,890 (unauthoritative)
 
100%[===============================>] 529,890      889.12K/s    ETA 00:00
 
17:38:36 (889.12 KB/s) - `dhcp-3.0pl2-6.16.i386.rpm.5' saved [529890]
 
[root@bigboy tmp]#

用DEB软件包安装软件

不像Redhat、Fedora和Centos这样的Linux发行版使用RPM包,Debian和Ubuntu使用的是DEB格式的软件包。此章节将讲解掌握其用法的几个最重要的问题。

如何手动安装DEB

总的来说,手动安装DEB文件有两种方法。其一是使用你事先下载到硬盘上的文件,其二是使用像光盘这样的移动存储来安装。

用下载的文件

将DEB文件(通常有一个后缀名“.deb”)下载到一个临时路径,比如/tmp。第二步是用dpkg --install命令来安装该软件包。下面有一个安装ndiswrapper utilities包的例子,是典型的用DEB安装命令来安装的例子:

root@u-bigboy:~# dpkg --install ndiswrapper-utils_1.8-0ubuntu2_i386.deb 
Selecting previously deselected package ndiswrapper-utils.
(Reading database ... 70221 files and directories currently installed.)
Unpacking ndiswrapper-utils (from ndiswrapper-utils_1.8-0ubuntu2_i386.deb) ...
Setting up ndiswrapper-utils (1.8-0ubuntu2) ...
root@u-bigboy:~#

用光盘

用光盘安装DEB文件和在Fedora和RedHat中的情况是类似的。区别在于光盘设备名称是/media/cdrom。下面的步骤将安装事先拷贝到光盘上的ndiswrapper DEB包:

1. 插入光盘,检查/media/cdrom路径下的文件,然后安装DEB。

root@u-bigboy:/tmp# mount /media/cdrom -o unhide
mount: block device /dev/hdc is write-protected, mounting read-only
root@u-bigboy:/tmp# cd /media/cdrom
root@u-bigboy:/media/cdrom# ls
ndiswrapper-utils_1.8-ubuntu2_i386.deb 
root@u-bigboy:/media/cdrom# dpkg --install ndiswrapper-utils_1.8-ubuntu2_i386.deb 
Selecting previously deselected package ndiswrapper-utils.
(Reading database ... 70221 files and directories currently installed.)
Unpacking ndiswrapper-utils (from ndiswrapper-utils_1.8-0ubuntu2_i386.deb) ...
Setting up ndiswrapper-utils (1.8-0ubuntu2) ...
root@u-bigboy:~#

2. 结束后,弹出光盘

root@u-bigboy:/media/cdrom# cd /tmp
root@u-bigboy:/tmp# umount /media/cdrom
root@u-bigboy:/tmp# eject cdrom
root@u-bigboy:/tmp#

注意:不像Fedora使用多张CD/DVD,Ubuntu是用一张CD/DVD盘发布的。Ubuntu安装进程从互联网上下载任何需要的软件包。因此,你可能发现使用APT工具要简单,它能够自动的下载安装大部分你要的软件包。下节会介绍APT工具。

DEB安装错误

有时候DEB软件的安装并不会按照你的计划来,而你此时就需要有正确的措施。有一些最常见的错误你很有可能会遇到,本节将告诉你如何从中恢复过来。

依赖失败(Failed Dependencies)

就像预想中的那样,软件包常常依赖其它一些已经安装的软件包。这可能会导致dpkg安装因依赖问题失败,而这就意味着有些必要的DEB要安装。在下一个例子中,我们要安装mrtg-contrib包,而他需要事先安装好mrtg包。

root@u-bigboy:/tmp# dpkg --install mrtg-contrib_2.12.2-1_all.deb 
Selecting previously deselected package mrtg-contrib.
(Reading database ... 70759 files and directories currently installed.)
Unpacking mrtg-contrib (from mrtg-contrib_2.12.2-1_all.deb) ...
dpkg: dependency problems prevent configuration of mrtg-contrib:
 mrtg-contrib depends on mrtg (= 2.12.2-1); however:
  Package mrtg is not installed.
dpkg: error processing mrtg-contrib (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mrtg-contrib
root@u-bigboy:/tmp#

在安装了mrtg包之后,mrtg-contrib安装成功。用APT工具你可以自动的安装依赖包。这在本章稍后会讲述。

如何列出已安装的DEB

dpkg --list命令会列出你系统中所有已安装的软件包。

root@u-bigboy:~# dpkg --list
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                Version             Description
+++-===================-===================-================================
ii  ssh                  4.1p1-7ubuntu4     Secure shell client and server
... 
...
...
root@u-bigboy:~#

命令的输出有6列:第4列是软件包的名称,第五列是包的版本,而最后的第6列是描述。

前面三列每个都是单字符宽,提供了包的详细信息,如表6-3:

表6-3 列格式的dpkg命令

期望状态

(Col. 1)

当前状态

(Col. 2)

错误状态

(Col. 3)

描述
u 未知(Unknown): 此包未安装
i 已安装(Installed): 特权用户已请求安装此包
r 移除(Remove): 特权用户已经请求移除此包,此包的配置文件很可能存在
p 清除(Purge): 先前安装的包已被移除,此包的配置文件也许亦被移除
h 保持(Hold): 特权用户已请求此包保持当前版本不自动升级
n 未安装(Not Installed): 此包未安装
i 已安装(Installed): 此包已安装
c 配置文件存在(Configuration Files Exist): 包被安装,而配置文件已经存在
u 解包(Unpacked): 文件已被解包,但是未安装
f 失败(Failed): 此包配置失败
h 停止(Halt): 此包安装失败,中途停止
h 强迫保持(Enforced Hold): 因为依赖包被定义为保持,此包的升级被搁置
r 重新安装(Reinstallation): 此包破损需要重新安装
x 此包破损且为强制保持

你可以用--list选项来指定你感兴趣的包,并显示它们。下面我们用这种方法,单独列出了openssh-server软件包。

root@u-bigboy:~# dpkg --list openssh-server
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                Version             Description
+++-===================-===================-========================================
ii  openssh-server      4.2p1-7ubuntu3      Secure shell server, an rshd replacement
root@u-bigboy:~#

如果你只对一个确切的包感兴趣,你可以将输出用管道重定向到grep命令。在下面的例子中,我们要找到所有名字中包含“dhcp”字符串的软件包。

root@u-bigboy:~# dpkg --list | grep dhcp
ii  dhcp3-client    3.0.2-1ubuntu6   DHCP Client
ii  dhcp3-common    3.0.2-1ubuntu6   Common files - dhcp3* packages
root@u-bigboy:~#

列出与DEB相关的文件

有时候,你安装软件的过程会因一个错误而中止,这个错误请求某一个文件要存在。很多情况下,安装程序并不说明在哪个包中可以找到这个文件。因此能够确定某些文件的来源很重要,而这可以通过列出你怀疑可能包含该文件的软件包的内容来实现。

列出已安装软件包的文件

如前所述,列出软件包中的文件很重要。用dpkg,--listfiles选项可以轻松提供这一信息。下面我们列出openssh-server软件包中的文件。

root@u-bigboy:~# dpkg --listfiles openssh-server
...
...
...
/var/run/sshd
/usr/lib/sftp-server
/usr/share/doc/openssh-server
root@u-bigboy:~#

列出DEB文件中的文件

下载网站上通常有一些包功能不同而名字相似。通过列出DEB包的内容来确认你的包是你想要的那个,是很好的方式。这可以通过dpkg的--contents选项来实现,如在这个例子中所见。

root@u-bigboy:/tmp# dpkg --contents openssh-server_4.2p1-7ubuntu3_i386.deb
...
...
... 
-rw-r--r-- root/root     10444 2006-05-17 17:43:19 ./usr/share/man/man8/sshd.8.gz
-rw-r--r-- root/root      1169 2006-05-17 17:43:19 ./usr/share/man/man8/sftp-server.8.gz
drwxr-xr-x root/root         0 2006-05-17 17:43:24 ./usr/share/doc/
drwxr-xr-x root/root         0 2006-05-17 17:43:24 ./usr/share/doc/openssh-client/
drwxr-xr-x root/root         0 2006-05-17 17:43:19 ./var/
drwxr-xr-x root/root         0 2006-05-17 17:43:19 ./var/run/
drwxr-xr-x root/root         0 2006-05-17 17:43:19 ./var/run/sshd/
...
...
...
root@u-bigboy:/tmp#

列出文件所属的软件包

搜索特定文件的所属包也可以通过dpkg的--search选项轻易实现。下面这个例子中,我们看到/etc/syslog.conf是sysklogd软件包的一部分。

root@u-bigboy:~# dpkg --search /etc/syslog.conf
sysklogd: /etc/syslog.conf
root@u-bigboy:~#

卸载DEB

dpkg --remove命令可以清除一个安装了的包,如下例:

root@u-bigboy:~# dpkg --remove ndiswrapper-utils
(Reading database ... 70241 files and directories currently installed.)
Removing ndiswrapper-utils ...
root@u-bigboy:~#

哪些包在启动时开始运行?

update-rc.d命令,你可以查看和配置哪些包在启动时开始运行。第7章"The Linux Boot Process"有对此更加详细的介绍。

用apt-get自动更新DEB

就像Fedora,Debian/Ubuntu Linux有它自己的包更新程序,此程序会自动地从基于仓库的网络中获取软件包。它叫做高级包工具(APT)。它最常用的命令是apt-get,稍后会更详细讲述此命令。

配置APT

APT使用/etc/apt/sources.list文件来说明你网络中的服务器,从中你可以找到你需要的包。此文件中的默认文件地址,可以参考一些可信的APT下载网站。

从/etc/apt/sources.list文件中列举的软件源中,周期性地同步APT包索引文件,是很重要的事情。它用包的最新版本列表来更新你的系统。这可以通过apt-get update命令实现,如下:

root@u-bigboy:/tmp# apt-get update
Get:1 http://security.ubuntu.com dapper-security Release.gpg [189B]         
Get:2 http://us.archive.ubuntu.com dapper Release.gpg [189B]
Get:3 http://us.archive.ubuntu.com dapper-updates Release.gpg [189B]
...
...
...
Fetched 184kB in 2s (66.1kB/s)                
Reading package lists... Done
root@u-bigboy:/tmp#

注意:如果你安装Ubuntu时无法接入互联网,你只能够安装最基本的软件包,/etc/apt/sources.list文件中的URL条目也会被注释掉。但是要安装的软件包会被标记,直到最后从dpkg数据库中安装它们。当你可以接入互联网时,取消对URL条目的注释,然后用apt-get命令来安装升级。这将从网上下载所有需要的包来升级你的系统。

如果你不想你所有的Debian/Ubuntu服务器都接入互联网,你也可以在你的网络中搭建一个APT服务器。你就必须相应地更新你的sources.list文件,但是对此的完整配置步骤超出了本书范围。

用APT保持系统最新

用upgrade选项,apt-get工具可以用来同时升级你系统中的所有软件包。若在其后没有列出任何软件包时就使用apt-get,它会试图更新所有包。“apt-get upgrage 包名”命令只更新指定DEB包。

在安装Linux后,因为要提升安全性和功能,使用apt-get来保证已安装了最新的软件通常是明智的做法。下面的例子显示了可能的输出(Here is an example of output of what to expect),-y标记会使apt-get在所有的询问中采取确认(“yes”),从而让其没有交互地径直运行下去:

root@u-bigboy:/tmp# apt-get -y upgrade
Reading package lists... Done
Building dependency tree... Done
The following packages have been kept back:
  linux-image-386
The following packages will be upgraded:
  capplets-data desktop-file-utils eog gdm gnome-about 
...
...
...
Setting up libgtk2.0-bin (2.8.18-0ubuntu1) ...
Updating the IM modules list for GTK+-2.4.0...done.
Updating the gdk-pixbuf loaders list for GTK+-2.4.0...done.

root@u-bigboy:/tmp#

用apt-get安装包的例子

下面是一个用apt-get安装软件包的例子,其中安装的包是apache网络服务器软件包。

[root@ root@u-bigboy:/tmp# apt-get -y install apache
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  apache-common apache2-utils libapr0 libpcre3
Suggested packages:
  apache-doc apache-ssl apache-perl
The following NEW packages will be installed:
  apache apache-common apache2-utils libapr0 libpcre3
...
...
... 
Creating config file /etc/apache/httpd.conf with new version

Creating config file /etc/apache/srm.conf with new version

Creating config file /etc/apache/access.conf with new version

Creating config file /etc/apache/modules.conf with new version
 * Starting apache 1.3 web server...
   ...done.

root@u-bigboy:/tmp#

记住下面APT的事实

  • APT工具的source.list文件主要列出使用TCP 80端口的URL(http:// ),来为APT的更新服务。这对你的防火墙规则很重要。
  • 运行“man sources.list”和“man apt-get”命令可以获取关于配置yum的更详细信息。

用tar文件安装软件

tar格式的文件是另外一种流行的软件安装文件。它们通常可以从软件开发者的主页或者如http://www.sourceforge.net 这样的在线软件库下载。

Linux里的tar命令用于档案文件,而且此文件通常有一个“.tar”文件后缀名。这些文件常常被压缩成gzip格式,而且在这种情况下,它们的后缀名将会是“.tar.gz”或者“.tgz”。从以上两种文件中提取数据的命令是类似的。当解压一个tar文件时,提取数据的命令是“tar -xvf 文件名.tar”。当解压档案文件时,要用的命令是“tar -xzvf 文件名.tar.gz”。

tar文件安装方法中,你首先要解压档案文件,并提取其中的内容放置在一个本地子目录中,这个子目录的名称通常和tar文件的名称是一样的。通常这个子目录里会有一个叫做README(读我)或者INSTALL(安装)的文件,其概述了安装软件所需的所有步骤。

下面是安装基于tar的软件的最初几个步骤:

1)输入从指定文件中提取数据的tar命令。

[root@bigboy tmp]# tar -xvzf linux-software-1.3.1.tar.gz
linux-software-1.3.1/
linux-software-1.3.1/plugins-scripts/
...
...
...
linux-software-1.3.1/linux-software-plugins.spec
[root@bigboy tmp]#

This creates a subdirectory with the installation files inside.

[root@bigboy tmp]# ls
linux-software-1.3.1  linux-software-1.3.1.tar.gz
[root@bigboy tmp]#

2)使用cd命令进入生成的子目录,并按照README和INSTALL文件中所列的指示来做:

[root@bigboy tmp]# cd linux-software-1.3.1
[root@bigboy linux-software-1.3.1]# ls
COPYING    install-sh   missing                 plugins
depcomp    LEGAL        mkinstalldirs           plugins-scripts
FAQ        lib          linux-software.spec     README
Helper.pm  Makefile.am  linux-software.spec.in  REQUIREMENTS
INSTALL    Makefile.in  NEWS                    subst.in
[root@bigboy linux-software-1.3.1]#

用tar文件安装软件,常常需要安装别的支持tar文件,而且每一个有各自特定的安装命令,这会让人很沮丧。与此相反,RPM或DEB用一个标准的命令格式就可以安装,而且用起来也很简单,这对Linux新手来说可能是更好的方法。

安装Perl模块

即使你不知道如何用Perl编程,你有时也不得不安装Perl模块来让你的软件包能够工作。

可以从主要的Perl模块网站http://www.cpan.org 下载TAR文件然后手动安装Perl模块。这种方法的缺点是不能够自动安装需要的依赖包。另外的一个缺点(尽管比较小)是,Perl模块名称里通常有一个双冒号(::),但是包含此模块的TAR安装文件的名称里没有双冒号。比如1.74版的Mail::Tools模块的名称为MailTools-1.74.tar.gz

也可以使用perl命令来自动安装Perl模块。本节我们会讲解这两种方法。

Perl模块的手动安装

大部分常用的Perl模块都可以从CPAN网站下载。其安装步骤也简单易懂。

1. 浏览CPAN网站,找到你需要的模块包,然后用类似wget的工具下载之。

[root@bigboy tmp]# wget http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
--15:07:36--  http://www.cpan.org/authors/id/M/MA/MARKOV/MailTools-1.74.tar.gz
           => `MailTools-1.74.tar.gz'
Resolving www.cpan.org... 66.39.76.93
Connecting to www.cpan.org|66.39.76.93|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 47,783 (47K) [application/x-tar]

100%[===================================>] 47,783       100.88K/s             

15:07:38 (100.51 KB/s) - `MailTools-1.74.tar.gz' saved [47783/47783]

[root@bigboy tmp]#

2. 用tar命令从模块包中提取文件。

[root@bigboy tmp]# tar -xzvf MailTools-1.74.tar.gz 
MailTools-1.74/
MailTools-1.74/t/
...
...
...
MailTools-1.74/ChangeLog
MailTools-1.74/MANIFEST
[root@bigboy tmp]#

3. 进入新建的和TAR文件名称相同的目录,然后使用如下命令来安装此模块。

  • perl Makefile.PL
  • make
  • make test
[root@bigboy tmp]# cd MailTools-1.74
[root@bigboy MailTools-1.74]# perl Makefile.PL
Checking for Net::SMTP...ok
Checking for Net::Domain...ok
Checking for IO::Handle...ok
Checking if your kit is complete...
Looks good
Writing Makefile for Mail
[root@bigboy MailTools-1.74]# make
cp Mail/Cap.pm blib/lib/Mail/Cap.pm
cp Mail/Mailer/rfc822.pm blib/lib/Mail/Mailer/rfc822.pm
...
...
...
Manifying blib/man3/Mail::Util.3pm
Manifying blib/man3/Mail::Address.3pm
[root@bigboy MailTools-1.74]# make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/extract.....ok                                                             
...
...
...
All tests successful.
Files=7, Tests=95,  2 wallclock secs ( 1.28 cusr +  0.29 csys =  1.57 CPU)
[root@bigboy MailTools-1.74]# 

你的Perl模块的安装现在应该就完成了。

注意:命令“perl Makefile.PL”的输出会告诉你,是否需要其余的一些模块。你可以全部都手动安装它们,同时冒着必须为这些依赖模块安装更多依赖模块的风险;或者你也可以用自动更新来安装,下面来讲解其具体事项。

Perl模块的自动安装

虽然用perl工具可以自动安装模块,但是在此之前你必须要安装其依赖ncftp包,来从CPAN下载模块包。

[root@bigboy tmp]# yum -y install ncftp

安装完这个模块包之后,你就可以使用如下的perl命令来进入CPAN工具。

perl -MCPAN -e shell

在其第一次运行时,Perl会提示你一些配置选项。大部分情况下使用默认配置就行了。在最初的安装完成后,你就有一个“cpan>”命令提示

cpan>

然后使用后接模块名的安装命令,就可以完成模块的安装了。在下面的例子中,我们用CPAN工具来安装Mail::Audit模块。

[root@bigboy tmp]# perl -MCPAN -e shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')

cpan> install Mail::Audit
CPAN: Storable loaded ok
LWP not available
CPAN: Net::FTP loaded ok
Fetching with Net::FTP:
  ftp://archive.progeny.com/CPAN/authors/01mailrc.txt.gz
...
...
...
Installing /usr/share/man/man3/Mail::Audit::MAPS.3pm
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
  /usr/bin/make install  -- OK

cpan> exit
Terminal does not support GetHistory.
Lockfile removed.
[root@bigboy tmp]#

你的Perl模块完全安装完成后,退出命令能让你退出到Linux命令提示界面。

总结

这仅仅只是个开始。如果你打算使你安装的软件让你的Linux计算机永久的运行一些程序,比如作为Web服务器、邮件服务器或者任何其它的服务器,你就必须知道如何在你的系统重新启动时就激活软件使其运行。这将会在第七章——"The Linux Boot Process(Linux引导过程)"中讲述。随后的章节将描述许多当前最流行的Linux服务器应用程序的使用、配置、测试和故障诊断方法。