程序包管理rpm&yum&编译安装

centos6.6程序包管理

二进制应用程序的组成部分:

二进制文件,库文件,配置文件和帮助文件
程序包管理器:rpm
rpm包管理器的前端工具:yum
程序包之间存在依赖关系

rpm的命名方式:

name_VERSION_release.arch.rpm
    VERSION: major.minor.release
        对应主版本号.次版本号.修订号
    release.arch:
        release: 包的发行号和对应的操作系统
        arch表示适用的平台
        X86: i386 i486 i586 i686
        X86_64: x86 x86_64 amd64
        noarch:表示此包可以安装到所有的平台上

例如:zsh-5.0.2-7.el7.x86_64.rpm

    zsh:软件名称
    5.0.2:软件版本
    7.el7:软件包发行商版本,7表示发行号,el7表示RHEL7
    x86_64:适用的平台

两个命令:ldd 和 ldconfig

程序包管理器rpm:

安装、升级、查询、卸载和校验

安装 -i :

    rpm {-i|--install} [install-options] PACKAGE_FILE ...
        -v或-vv:显示安装过程详情,-vv显示更详细的安装信息
        -h:以#显示程序包安装的进度,每个#表示2%的进度

安装和升级选项【INSTALL AND UPGRADE OPTIONS】:

--test Do not install the package, simply check for and report potential conflicts.测试安装,但不真正的执行安装
--nodeps
       Don’t do a dependency check before installing or upgrading a package.忽略依赖关系,直接进行安装
--replacepkgs
       Install the packages even if some of them are already installed on this system.替换安装,重新安装
 --ignoreos
       Allow  installation or upgrading even if the operating systems of the binary package and host
       don’t match. 忽略操作系统是否匹配
--nosignature
       Don’t verify package or header signatures when reading.不检查包签名(即不检查来源)
--oldpackage
       Allow an upgrade to replace a newer package with an older one.降级
--noscripts 不执行程序包脚本
--nopre 不执行安装前脚本
--nopost不执行安装后脚本
--nopreun 不执行卸载前脚本
--nopostun不执行卸载后脚本

          

升级-U -F:

rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
如果已安装旧版程序包则升级,不存在则直接安装
rpm {-F|--freshen} [install-options] PACKAGE_FILE ...
如果已存在旧版程序包则升级,不存在则不安装

实例:

    没有依赖的应用可以直接安装成功:

[root@scm-dzm Packages]# pwd
/media/CentOS_6.6_Final/Packages 虚拟机光盘下Packages
[root@scm-dzm Packages]# rpm -ivh tree-1.5.3-2.el6.i686.rpm
Preparing...                ########################################### [100%]
   1:tree                   ########################################### [100%]

    有依赖的包需要先安装依赖的包:

[root@scm-dzm Packages]# rpm -ivh tomcat6-6.0.24-80.el6.i686.rpm        
error: Failed dependencies:
        jakarta-commons-collections is needed by tomcat6-0:6.0.24-80.el6.i686
        jakarta-commons-daemon is needed by tomcat6-0:6.0.24-80.el6.i686
        jakarta-commons-dbcp is needed by tomcat6-0:6.0.24-80.el6.i686
        jakarta-commons-logging is needed by tomcat6-0:6.0.24-80.el6.i686
        jakarta-commons-pool is needed by tomcat6-0:6.0.24-80.el6.i686
        log4j is needed by tomcat6-0:6.0.24-80.el6.i686
        mx4j is needed by tomcat6-0:6.0.24-80.el6.i686
        tomcat6-lib = 0:6.0.24-80.el6 is needed by tomcat6-0:6.0.24-80.el6.i686

查询-q:

rpm {-q|–query} [select-options] [query-options]

查询选项[select-options]:

-a, –all

              Query all installed packages. 查询所有已安装的包

            -p, –package PACKAGE_FILE

              Query an (uninstalled) package PACKAGE_FILE. 查询未安装包的信息,与{i|l|c|d|R}结合使用

            -f, –file FILE

              Query package owning FILE.

            –whatprovides CAPABILITY 

              Query all packages that provide the CAPABILITY capability.查询CAPABILITY由哪个包提供或生成

            –whatrequires CAPABILITY

              Query all packages that require CAPABILITY for proper functioning.查询CAPABILITY被谁所依赖

        [query-options]

            –changelog

              Display change information for the package.查询rpm包的修改记录

            -c, –configfiles

              List only configuration files (implies -l).查询包的配置文件

            -l, –list

              List files in package.

            -c, –configfiles

              List only configuration files (implies -l).

            -d, –docfiles

              List only documentation files (implies -l).

            –scripts

              List  the  package  specific scriptlet(s) that are used as part of the installation and unin-

              stallation processes.

            -R, –requires

              List capabilities on which this package depends.

            –provides

              List capabilities this package provides.

常用方式:

    安装

    rpm -ivh PACKAGE_FILE

    升级

    rpm -Fvh PACKAGE_FILE

    rpm -Uvh PACKAGE_FILE

    查询

    rpm -qa 查询所有已安装的包

    rpm -qa |grep tree 查询某一个已安装的包,其结果为tree-1.5.3-2.el6.i686

    rpm -ql vim-common-7.2.411-1.8.el6.i686

    rpm -qc vim-common-7.2.411-1.8.el6.i686

    rpm -qd vim-common-7.2.411-1.8.el6.i686

    rpm -q –scripts vim-common-7.2.411-1.8.el6.i686

    rpm -qR tree-1.5.3-2.el6.i686

    rpm -qpi tomcat6-6.0.24-80.el6.i686.rpm

    例子:

     [root@scm-dzm Packages]# rpm -qc vim-minimal

     /etc/virc

卸载:

rpm {-e|–erase} [–allmatches] [–nodeps] [–noscripts] [–notriggers] [–test] PACKAGE_NAME …

rpm -evv --test tree 测试卸载
rpm -evv tree 卸载tree
rpm -evv --nodeps tree 忽略依赖卸载tree

检验:

rpm {-V|–verify} [select-options] [verify-options]

rpm --import RPM-GPG-KEY-CentOS-7
如果rpm的数据库文件损坏,就需要做如下操作:
rpm --initdb初始化
rpm --rebuilddb重建

程序包管理之前端工具yum

yum是c/s架构的

配置yum:

/etc/yum.conf 各个yum仓库的公共配置
/etc/yum.repos.d/*.repo 为仓库的指向提供配置

先安装工具:yum install createrepo -y

创建一个本地yum仓库,我是拷贝iso下的packages文件夹到本地yumrepo下:

1、目录yumrepo下Packages,所有包都放于Packages下:
[root@scm-dzm yumrepo]# ls
Packages
[root@scm-dzm yumrepo]# createrepo Packages/
在Packages下生成元数据repodata
2、 配置
vi /etc/yum.repos.d/localyum.repo
[mybase]
name=local repo
baseurl=file:///home/yumrepo/Packages/
gpgcheck=0
3、 查看
yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
mybase                                              | 2.9 kB     00:00 ... 
mybase/primary_db                                   | 2.8 MB     00:00 ... 
repo id                               repo name                                   status
base                                  CentOS-6 - Base                             5,062
extras                                CentOS-6 - Extras                           39
mybase                                local repo                                  3,271
updates                               CentOS-6 - Updates                           102
repolist: 8,474

yum命令的使用:

显示仓库列表

yum repolist

显示程序包

yum list [all] 默认是all
yum list installed
yun list update
yum list extras 已安装但不在yum仓库的软件包

安装程序包,yum可以自动解决依赖关系

yum install PACKAGES [PACKAGES1] [PACKAGES2] [...]
例如:yum install tree

升级程序包

yum update PACKAGES [PACKAGES1] [PACKAGES2] [...]
例如:yum update firefox -y

检查升级

yum check-update

卸载程序包

yum remove | erase  [PACKAGES1] [PACKAGES2] […]

检查程序包的信息

yum info [PACKAGES1]

[root@scm-dzm ~]# yum info firefox
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
     * base: mirrors.tuna.tsinghua.edu.cn
     * extras: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.tuna.tsinghua.edu.cn
    Installed Packages
    Name        : firefox
    Arch        : i686
    Version     : 31.1.0
    Release     : 5.el6.centos
    Size        : 108 M
Repo        : installed
From repo   : anaconda-CentOS-201410241409.i386
Summary     : Mozilla Firefox Web browser
URL         : http://www.mozilla.org/projects/firefox/
License     : MPLv1.1 or GPLv2+ or LGPLv2+
Description : Mozilla Firefox is an open-source web browser, designed for standards
            : compliance, performance and portability.
Available Packages
Name        : firefox
Arch        : i686
Version     : 45.2.0
Release     : 1.el6.centos
Size        : 75 M
Repo        : updates
Summary     : Mozilla Firefox Web browser
URL         : http://www.mozilla.org/projects/firefox/
License     : MPLv1.1 or GPLv2+ or LGPLv2+
Description : Mozilla Firefox is an open-source web browser, designed for standards
            : compliance, performance and portability.

查看指定特性由哪个程序包提供

yum provides tree 或者yum provides /usr/bin/tree
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
tree-1.5.3-3.el6.i686 : File system tree viewer
Repo        : base
Matched from:
Filename    : /usr/bin/tree
tree-1.5.3-2.el6.i686 : File system tree viewer
Repo        : mybase
Matched from:
Filename    : /usr/bin/tree
tree-1.5.3-2.el6.i686 : File system tree viewer
Repo        : installed
Matched from:
Other       : Provides-match: /usr/bin/tree

清理本地缓存

yum clear [packages|matedate|expire-cache|rpmdb|plugins]

例如:

[root@scm-dzm ~]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras mybase updates
Cleaning up Everything
Cleaning up list of fastest mirrors

创建缓存|构建缓存

yum makecache

例如:

[root@scm-dzm ~]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * base: mirrors.neusoft.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
base                                          | 3.7 kB     00:00     
base/group_gz                                 | 220 kB     00:00     
base/filelists_db                             | 5.3 MB     00:08     
base/primary_db                               | 3.7 MB     00:06     
base/other_db                                 | 1.5 MB     00:01 ETA base/other_db                                      | 2.1 MB     00:07     
extras                                        | 3.3 kB     00:00     
extras/filelists_db                           |  35 kB     00:00     
extras/prestodelta                            |   78 B     00:00     
extras/primary_db                             |  30 kB     00:00     
extras/other_db                               |  46 kB     00:00     
mybase                                        | 2.9 kB     00:00 ... 
mybase/filelists_db                           | 3.7 MB     00:01 ... 
mybase/primary_db                             | 2.8 MB     00:01 ... 
mybase/other_db                               | 1.5 MB     00:00 ... 
updates                                       | 3.4 kB     00:00     
updates/filelists_db                          | 507 kB     00:00     
updates/prestodelta                           |  36 kB     00:00     
updates/primary_db                            | 707 kB     00:00     
updates/other_db                              | 7.5 MB     00:15     
Metadata Cache Created

搜索:指定关键字搜索包名以及summary

yum search string

例如

[root@scm-dzm ~]# yum search fire
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.neusoft.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
================================================ N/S Matched: fire ================================================
firefox.i686 : Mozilla Firefox Web browser
system-config-firewall.noarch : A graphical interface for basic firewall setup
system-config-firewall-base.noarch : system-config-firewall base components and command line tool
system-config-firewall-tui.noarch : A text interface for basic firewall setup
  Name and summary matches only, use "search all" for everything.

重新安装

yum reinstall [PACKAGES1] [PACKAGES2] […]

降级安装

yum downgrade [PACKAGES1] [PACKAGES2] […]

查看yum事务历史

yum history 

例如:

[root@scm-dzm ~]# yum history info
Loaded plugins: fastestmirror, refresh-packagekit, security
Transaction ID : 7
Begin time     : Fri Jun 24 23:03:25 2016
Begin rpmdb    : 1117:bdc4d0fbd9dce392894d7015690d4043356bb307
End time       :            23:03:37 2016 (12 seconds)
End rpmdb      : 1117:bdc4d0fbd9dce392894d7015690d4043356bb307
User           : root <root>
Return-Code    : Success
Command Line   : reinstall samba
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.i686                         @anaconda-CentOS-201410241409.i386/6.6
    Installed     yum-3.2.29-60.el6.centos.noarch               @anaconda-CentOS-201410241409.i386/6.6
    Installed     yum-plugin-fastestmirror-1.1.30-30.el6.noarch @anaconda-CentOS-201410241409.i386/6.6
Packages Altered:
    Reinstall samba-3.6.23-35.el6_8.i686 @updates
history info

本地安装

yum  localinstall rpmfile

包组管理

yum groupinstall group1 [group2] […]

        yum groupupdate group1 [group2] […]

        yum grouplist [hidden] [groupwildcard] […]

        yum groupremove group1 [group2] […]

        yum groupinfo group1 […]

yum的选项:

    常用的-y,自动选择yes
    --nogpgcheck禁止进行gpgcheck
    -q:静默模式--quiet
    --disablerepo=repoidglob 临时禁用仓库
    --enablerepo=repoidglob 临时启用仓库
    --noplugins禁用所有插件

手动安装软件包:

    1)configure      检测编译环境
    2)make           进行编译
    3)make install   编译安装

实例:

下载httpd源码地址 http://httpd.apache.org/download.cgi
tar -zxf httpd-2.2.31.tar.gz 
cd httpd-2.2.31/
./configure --help
./configure --prefix=/usr/local/apache2
make
make install

原创文章,作者:Net20_天意,如若转载,请注明出处:http://www.178linux.com/22789

(0)
Net20_天意Net20_天意
上一篇 2016-07-07 10:52
下一篇 2016-07-07 18:47

相关推荐

  • 计算机组成及各部分功能

    计算机组成及各部分功能 计算机组成 区别于利用机械原理对数据进行处理的机械计算机,计算机现在一般都指电子计算机,即电脑。计算机是一种利用电子学原理,根据一些列指令对数据进行处理的工具。 不管是机械计算机还是电子计算机其主要目的还是代替人来完成一系列的数据计算。1941年夏天诞生的阿塔纳索夫-贝瑞计算机是世界上第一部电子计算机,使用了真空管计算器,二进制数值,…

    Linux干货 2016-10-27
  • 网卡名称更改

    网卡是计算机进行网络通信的必须的设备。在CentOS6及其更早的系统中,网卡设备在系统中的名称命名为eth#(#为0,1,2…之类的数字)。在内核版本为3.0.0及其以后的Linux发行版中,网卡设备在系统中名称变得很长,变得不好识别以及不利于管理。为了更好的管理,我们将新的网络设备命名改为传统的命名。 网卡名称更改 在CentOS系统中操作 在RHEL7系…

    Linux干货 2016-11-23
  • 马哥教育网络第21期-第八周课程练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。   网桥从一个局域网接收MAC帧,拆封、校对、校验之后,按另一个局域网的格式重新组装,发往它的物理层。由于网桥是链路层设备,因此不处理数据链路层以上层次协议所加的报头。   集线器的主要功能是对接收到的信号进行再生整形放大,以扩大网络的传输距离,同时把所有节点…

    Linux干货 2016-10-24
  • 01

    0101

    Linux干货 2016-08-08
  • linux用户和组的配置文件

    1./etc/passwd:用户及其属性信息(用户名,密码,uid,gid,gecos注释性描述信息,家目录,登录shell)在/etc/passwd文件中每个用户都有一个对应的记录行,它记录了这个用户的一些基本属性。系统管理员经常会接触到这个文件的修改以完成对用户的管理工作。这个文件对所有用户都是可读的。      …

    2017-07-22
  • linux基础学习-第六天

    2016-08-02 授课内容: 用户和组管理命令 理解并设置文件权限 默认权限 特殊权限 文件ACL 用户和组管理命令 用户和组的配置文件:/etc/default/useradd(相当于useradd -D)、/etc/skel(创建用户的家目录配置文件)、/etc/login.defs(修改用户的密码策略配置) /etc/default/useradd…

    Linux干货 2016-08-04