分类: LINUX
2011-01-24 20:21:35
关于linux下面如何管理软件包的讨论,
Linux下面安装软件包的介绍
在linux系统中管理软件包有两种方法,第一种就是利用yum的方式来管理软件包。第二种就是利用rpm的方法来管理软件包。Yum与rpm的区别在于rpm在安装软件包的时候解决不了软件包依赖性关系,而yum在安装软件包的时候很好的解决了软件包的依赖性关系,很强大。
下面首先来讲解利用yum来管理软件包。
Yum介绍
Yum全称为 Yellow dog Updater, Modified(软件包管理器)
主要功能是更方便的添加/删除/更新RPM包, yum很好的解决了linux下面安装软件包的依赖性关系。很强大哦! 他能便于管理大量系统的更新问题 ,能同时设置多个资源库(Repository),而且使用起来十分的方便。
如果想使用yum的方式来安装软件包,那么必须配置yum仓库。
关于yum仓库的配置方法可以参考:
http://blog.chinaunix.net/u3/111899/showart_2197778.html
1. 利用yum的方式来安装软件包
#yum -y install vsftpd
-y 不用交互式
Install 安装
Vsftpd 需要安装软件包(这个是软件包,而不是软件包的rpm文件名)
[root@localhost ~]#
[root@localhost ~]# yum -y install vsftpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Cluster | 1.3 kB 00:00
Cluster/primary | 6.5 kB 00:00
Cluster 32/32
ClusterStorage | 1.3 kB 00:00
ClusterStorage/primary | 8.8 kB 00:00
ClusterStorage 39/39
Server | 1.3 kB 00:00
Server/primary | 732 kB 00:00
Server 2292/2292
VT | 1.3 kB 00:00
VT/primary | 9.0 kB 00:00
VT 36/36
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.i386 0:2.0.5-16.el5 set to be updated
Cluster/filelists | 110 kB 00:00
ClusterStorage/filelists | 11 kB 00:00
Server/filelists | 2.3 MB 00:00
VT/filelists | 26 kB 00:00
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vsftpd i386 2.0.5-16.el5 Server 140 k
Transaction Summary
================================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 140 k
Downloading Packages:
vsftpd-2.0.5-16.el5.i386.rpm | 140 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : vsftpd 1/1
Installed:
vsftpd.i386 0:2.0.5-16.el5
Complete!
[root@localhost ~]#
这样我们就利用yum的方式安装成功了ftp服务。
2. 利用yum的方式来安装本地软件包
# yum -y install dovecot-1.0.7-7.el5.i386.rpm
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg dovecot-1.0.7-7.el5.i386.rpm install.log server.repo
Desktop grub.conf install.log.syslog
[root@localhost ~]# yum -y install dovecot-1.0.7-7.el5.i386.rpm
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Examining dovecot-1.0.7-7.el5.i386.rpm: dovecot-1.0.7-7.el5.i386
Marking dovecot-1.0.7-7.el5.i386.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package dovecot.i386 0:1.0.7-7.el5 set to be updated
--> Processing Dependency: libmysqlclient.so.15 for package: dovecot
--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: dovecot
--> Processing Dependency: libpq.so.4 for package: dovecot
--> Running transaction check
---> Package mysql.i386 0:5.0.77-3.el5 set to be updated
--> Processing Dependency: perl(DBI) for package: mysql
---> Package postgresql-libs.i386 0:8.1.11-1.el5_1.1 set to be updated
--> Running transaction check
---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
dovecot i386 1.0.7-7.el5 /dovecot-1.0.7-7.el5.i386 3.6 M
Installing for dependencies:
mysql i386 5.0.77-3.el5 Server 4.8 M
perl-DBI i386 1.52-2.el5 Server 605 k
postgresql-libs i386 8.1.11-1.el5_1.1 Server 196 k
Transaction Summary
================================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total size: 9.1 M
Total download size: 5.5 M
Downloading Packages:
(1/3): mysql-5.0.77-3.el5.i386.rpm | 4.8 MB 00:00
(2/3): postgresql-libs-8.1.11-1.el5_1.1.i386.rpm | 196 kB 00:00
(3/3): perl-DBI-1.52-2.el5.i386.rpm | 605 kB 00:00
--------------------------------------------------------------------------------
Total 7.3 MB/s | 5.5 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-DBI 1/4
Installing : mysql 2/4
Installing : postgresql-libs 3/4
Installing : dovecot 4/4
Installed:
dovecot.i386 0:1.0.7-7.el5
Dependency Installed:
mysql.i386 0:5.0.77-3.el5 perl-DBI.i386 0:1.52-2.el5
postgresql-libs.i386 0:8.1.11-1.el5_1.1
Complete!
[root@localhost ~]#
安装本地软件包的意义在于如果我们从互联网上面下载了一个rpm软件包,这个软件包用rpm方式安装可能会提示有依赖性关系,这个时候可以使用本地安装的方式来安装,因为我们的yum仓库有可能会解决这个包的依赖性关系。
但是这个后面接的是一个软件包rpm文件名,而不是软件包。
3. 利用yum使用组的方式来安装软件包
我们如何去查询那些组是可以安装的呢,
使用下面这条命令
#yum grouplist
[root@localhost ~]#
[root@localhost ~]# yum grouplist
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Group Process
Cluster/group | 101 kB 00:00
ClusterStorage/group | 105 kB 00:00
Server/group | 1.0 MB 00:00
VT/group | 103 kB 00:00
Installed Groups:
Administration Tools
Editors
FTP Server
GNOME Desktop Environment
Graphical Internet
Graphics
Legacy Network Server
Mail Server
MySQL Database
Network Servers
Office/Productivity
Printing Support
Server Configuration Tools
Sound and Video
System Tools
Text-based Internet
X Window System
Available Groups:
Authoring and Publishing
Cluster Storage
Clustering
DNS Name Server
Development Libraries
Development Tools
Engineering and Scientific
GNOME Software Development
Games and Entertainment
Java Development
KDE (K Desktop Environment)
KDE Software Development
Legacy Software Development
Legacy Software Support
News Server
OpenFabrics Enterprise Distribution
PostgreSQL Database
Virtualization
Web Server
Windows File Server
X Software Development
Done
[root@localhost ~]#
在这个命令里面显示的软件包都是可以使用组的方式来安装的。
下面我们利用组的方式来安装。
# yum -y groupinstall "DNS Name Server"
[root@localhost ~]#
[root@localhost ~]# yum -y groupinstall "DNS Name Server"
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Group Process
Resolving Dependencies
--> Running transaction check
---> Package bind.i386 30:9.3.6-4.P1.el5 set to be updated
---> Package bind-chroot.i386 30:9.3.6-4.P1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
bind i386 30:9.3.6-4.P1.el5 Server 978 k
bind-chroot i386 30:9.3.6-4.P1.el5 Server 44 k
Transaction Summary
================================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 1.0 M
Downloading Packages:
(1/2): bind-9.3.6-4.P1.el5.i386.rpm | 978 kB 00:00
(2/2): bind-chroot-9.3.6-4.P1.el5.i386.rpm | 44 kB 00:00
--------------------------------------------------------------------------------
Total 2.9 MB/s | 1.0 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : bind 1/2
Installing : bind-chroot 2/2
Installed:
bind.i386 30:9.3.6-4.P1.el5 bind-chroot.i386 30:9.3.6-4.P1.el5
Complete!
[root@localhost ~]#
我们知道安装DNS服务需要安装三个包,而我们利用组的方式来安装软件包,系统会自动的安装所有DNS服务需要的软件包,很方便。
4. 利用yum的方式来卸载软件包
#yum -y remove vsftpd
[root@localhost ~]#
[root@localhost ~]# yum -y remove vsftpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.i386 0:2.0.5-16.el5 set to be erased
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
vsftpd i386 2.0.5-16.el5 installed 285 k
Transaction Summary
================================================================================
Install 0 Package(s)
Update 0 Package(s)
Remove 1 Package(s)
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : vsftpd 1/1
Removed:
vsftpd.i386 0:2.0.5-16.el5
Complete!
[root@localhost ~]#
卸载的时候也是接软件包,而不是软件包的rpm文件名。
5. 利用yum的方式来更新软件包
#yum update
[root@localhost ~]#
[root@localhost ~]# yum update
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Skipping security plugin, no data
Setting up Update Process
No Packages marked for Update
[root@localhost ~]#
这个是更新全部的软件包
#yum update vsftpd
[root@localhost ~]#
[root@localhost ~]# yum update vsftpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Skipping security plugin, no data
Setting up Update Process
No Packages marked for Update
[root@localhost ~]#
这个更新指定的软件包(也是接软件包)
#yum check-update
[root@localhost ~]#
[root@localhost ~]# yum check-update
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Skipping security plugin, no data
[root@localhost ~]#
这个检查可更新的软件包。
6. 利用yum来查询软件包
#yum search vsftpd
[root@localhost ~]#
[root@localhost ~]# yum search vsftpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
=============================== Matched: vsftpd ================================
vsftpd.i386 : vsftpd - Very Secure Ftp Daemon
[root@localhost ~]#
这个是查询指定的软件包
#yum list all
列出系统中所有的软件,包括安装的和未安装的。
#yum list all | grep vsftpd
[root@localhost ~]#
[root@localhost ~]# yum list all |grep vsftpd
This system is not registered with RHN.
RHN support will be disabled.
vsftpd.i386 2.0.5-16.el5 installed
[root@localhost ~]#
通过查询,可以看到,vsftpd已经安装了。这个命令也很好用。
#yum list available
查询系统中没有安装的软件包
#yum list installed
查询系统中安装的软件包
#yum info vsftpd
[root@localhost ~]#
[root@localhost ~]# yum info vsftpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Installed Packages
Name : vsftpd
Arch : i386
Version : 2.0.5
Release : 16.el5
Size : 285 k
Repo : installed
Summary : vsftpd - Very Secure Ftp Daemon
URL :
License : GPL
Description: vsftpd is a Very Secure FTP daemon. It was written completely from
: scratch.
[root@localhost ~]#
查询软件包的详细信息。
#yum whatprovides /etc/inittab
[root@localhost ~]#
[root@localhost ~]# yum whatprovides /etc/inittab
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
initscripts-8.45.30-2.el5.i386 : The inittab file and the /etc/init.d scripts.
Repo : Server
Matched from:
Filename : /etc/inittab
initscripts-8.45.30-2.el5.i386 : The inittab file and the /etc/init.d scripts.
Repo : installed
Matched from:
Other : Provides-match: /etc/inittab
[root@localhost ~]#
这个是查询某个文件是属于那个包的。
#yum clean all
清除缓存信息
Yum的使用方法到这里就基本完成了。
下面首先讲解利用rpm来管理软件包。
Rpm介绍
Rpm的全称为RedHat package manager(红帽软件包管理器),虽然rpm的方式并不可以解决软件包的依赖性关系,但是rpm的查询方式也是非常的强大的。
1. 利用rpm的方式来安装软件包
#rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm
[root@localhost ~]#
[root@localhost ~]# ls | grep vsftpd-2.0.5-16.el5.i386.rpm
vsftpd-2.0.5-16.el5.i386.rpm
[root@localhost ~]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm
Preparing... ########################################### [100%]
1:vsftpd ########################################### [100%]
[root@localhost ~]#
-v h 输出选项
利用rpm安装软件包一定是接软件包的rpm文件名。
# rpm -Fvh vsftpd-2.0.5-16.el5.i386.rpm
# rpm -Uvh vsftpd-2.0.5-16.el5.i386.rpm
这两条命令的区别在于
-Fvh 原来安装了软件包就更新,没有安装就不管。只更新。
-Uvh 原来安装了软件包就更新,没有安装就自动安装。
2. 利用rpm的方法来卸载软件包
#rpm -evh vsftpd
[root@localhost ~]#
[root@localhost ~]# rpm -e vsftpd
[root@localhost ~]#
用rpm卸载软件包的时候要注意后面只可以接软件包。
3. 利用rpm重新安装软件包
# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm -- replacepkgs
[root@localhost ~]#
[root@localhost ~]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm --replacepkgs
Preparing... ########################################### [100%]
1:vsftpd ########################################### [100%]
[root@localhost ~]#
# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm -- force
这两条命令的作用都是一样的,都是重新安装软件包,它们的区别在于—replacepkgs在系统正常运行的时候可以使用这个,但是在修复模式下面只可以使用—force。
在利用rpm安装软件包的时候,可以使用url的方式来安装软件包。
#rpm –ivh
4. 利用rpm来查询软件包
#rpm -qa
查询系统中所有已经安装的软件包
#rpm -qa | grep vsftpd
[root@localhost ~]#
[root@localhost ~]# rpm -qa | grep vsftpd
vsftpd-2.0.5-16.el5
[root@localhost ~]#
查询vsftpd这个软件包有没有安装
#rpm -q vsftpd
查询vsftpd这个软件包有没有安装,和上面一样。
#rpm -qf /etc/inittab
[root@localhost ~]#
[root@localhost ~]# rpm -qf /etc/inittab
initscripts-8.45.30-2.el5
[root@localhost ~]#
查询文件是属于那个软件包的。
# rpm –qpi dovecot-1.0.7-7.el5.i386.rpm
[root@localhost ~]#
[root@localhost ~]# rpm -qpi dovecot-1.0.7-7.el5.i386.rpm
Name : dovecot Relocations: (not relocatable)
Version : 1.0.7 Vendor: Red Hat, Inc.
Release : 7.el5 Build Date: Tue 25 Nov 2008 12:47:16 AM CST
Install Date: (not installed) Build Host: hs20-bc1-2.build.redhat.com
Group : System Environment/Daemons Source RPM: dovecot-1.0.7-7.el5.src.rpm
Size : 3730313 License: LGPL
Signature : DSA/SHA1, Wed 10 Dec 2008 08:42:34 PM CST, Key ID 5326810137017186
Packager : Red Hat, Inc. <
URL :
Summary : Dovecot Secure imap server
Description :
Dovecot is an IMAP server for Linux/UNIX-like systems, written with security
primarily in mind. It also contains a small POP3 server. It supports mail
in either of maildir or mbox formats.
[root@localhost ~]#
查询一个没有安装软件包的信息。
#rpm -ql vsftpd
查询vsftpd这个服务产生了那些文件。
#rpm -ivh --nodeps dovecot-1.0.7-7.el5.i386.rpm
去掉软件包的依赖性关系,但是前提是你已经知道了去掉依赖性关系后的软件包,你的服务也没有问题。
5. rpm的校验
#rpm -V vsftpd
校验rpm软件包是否有问题。
#rpm -Vp vsftpd-2.0.5-16.el5.i386.rpm
和上面一样,也是校验rpm软件包是否有问题。
#rpm -Va
校验所有的rpm软件包。
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
利用rpm第一次安装软件包的时候必须导入这个gpg-key。
6. 利用rpm来升级内核
# rpm -ivh kernel-PAE-2.6.18-164.el5.i686.rpm
[root@localhost ~]#
[root@localhost ~]# ls | grep kernel
kernel-PAE-2.6.18-164.el5.i686.rpm
[root@localhost ~]# rpm -ivh kernel-PAE-2.6.18-164.el5.i686.rpm
Preparing... ########################################## [100%]
1:kernel-PAE ########################################### [100%]
[root@localhost ~]#
这样我们的内核就安装成功了。
安装成功内核以后,我们可以去/boot/grub/grub.conf文件中定义从新内核启动。
在linux下面软件包管理讨论就到这里了。