个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
用DEB文件安装软件
删除Installing Software From RPM Files
第217行: 第217行:
 
    
 
    
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
 
=Installing Software From RPM Files=
 
 
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.
 
 
 
 
== How To Install RPMs Manually ==
 
 
 
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.
 
  
 
=用DEB软件包安装软件=
 
=用DEB软件包安装软件=

2010年6月21日 (一) 01:46的版本

简介

当你第一次在你的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的更详细信息。

Installing Software Using tar Files

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.

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.

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.

Here are the initial steps to take to install tar-based software:

1) Issue the tar command to extract the files.

[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) Use the cd command to enter the subdirectory and follow the directions listed in the INSTALL and README files:

[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]#

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.

Installing Perl Modules

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.

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 Mail::Tools module has the file name MailTools-1.74.tar.gz.

Modules can also be installed automatically using the perl command. We will cover both methods in this section.

Manual Installation of Perl Modules

Most of the commonly used Perl modules can be downloaded from the CPAN website. The installation steps are straightforward.

1. Browse the CPAN website, identify the module package you need and then download it using a utility such as 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. Extract the file from the package with the tar command.

[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. Enter the newly created directory with the same name as the TAR file, and install the module with the following commands.

  • 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]# 

Your Perl module installation should now be complete.

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.

Automatic Installation of Perl Modules

Modules can be installed automatically using the perl utility but you must first install the prerequisite ncftp package to download the packages from CPAN.

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

After the package installed you can use the following perl command to enter the CPAN utility.

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

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 Mail::Audit module using the CPAN utility.

[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]#

The exit command allows you to return to the Linux command prompt and your Perl module should be fully installed.

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, "The Linux Boot Process". Subsequent chapters cover the use, configuration, testing, and troubleshooting of many of the most popular Linux server applications used today.