学习目标

  1. 能够针对rpm软件包进行管理
  2. 能够对yum源软件进行管理
  3. 能够对源码包进行管理

一、RPM包管理

RPM全名是[RedHat Package Manager,是由Red Hat公司开发出来,由于非常好用,目前被很多linux发行版使用。

特点:

  1. 由于已经编译打包完毕,所以软件传输与安装很方便
  2. 查询、升级方便

1. RPM软件包常用命令

命令 作用
rpm -ivh filename.rpm 安装软件
rpm -Uvh filename.rpm 升级软件
rpm -e filename.rpm 卸载软件
rpm -qpi filename.rpm 查询软件的描述信息
rpm -qa 查询系统中所有的rpm软件

2. 案例

  1. # 查看系统中是否已经安装了firefox
  2. [root@itcast ~]# rpm -qa | grep firefox
  3. firefox-24.5.0-1.el7.centos.x86_64
  4. # 如果安装先进行卸载
  5. [root@itcast ~]# rpm -e firefox
  6. # 进入系统镜像中的Packages目录
  7. [root@itcast Packages]# rpm -ivh firefox-24.5.0-1.el7.centos.x86_64.rpm
  8. 准备中... ################################# [100%]
  9. 正在升级/安装...
  10. 1:firefox-24.5.0-1.el7.centos ################################# [100%]

RPM虽然能够使软件安装变得方便,但是在安装软件的时候依赖关系仍然需要自己解决,有些大型软件需要十多个依赖包,安装会变得复杂。这时候有进一步简化RPM管理软件的方式yum安装。

二、yum软件管理

yum软件管理是为了进一步简化RPM管理软件难度而设计的,yum能够根据用户的需求分析出所需软件包及相关依赖关系,自动从服务器下载软件包并安装到系统。

yum软件仓库:yum在下载软件时存放软件包的远程服务器

1. yum常用命令

命令 作用
yum remove 软件包 移除软件包
yum [-y] install 软件包名称 安装软件包(加y在安装时候不用输入y确认)
yum update 软件包名称 升级软件包
yum list installed 查看已安装软件包

2. 案例

  1. # 查看是否安装了firefox
  2. [root@itcast Packages]# yum list installed | grep firefox
  3. firefox.x86_64 24.5.0-1.el7.centos @anaconda
  4. [root@itcast Packages]# yum remove firefox
  5. 移除 1 软件包
  6. 安装大小:87 M
  7. 是否继续?[y/N]: //此处输入y
  8. [root@itcast Packages]# yum install firefox

三、源码包管理

源码包,提供了源代码需要进行配置编译才能进行操作的一种软件包形式

特点:

  1. 安装比较麻烦,需要配置编译等过程才能安装
  2. 升级、卸载不方便
  3. 需要手工解决依赖关系
  4. 用户可以修改软件代码

1. 源码包的安装步骤

  1. ./configure
    创建Makefile文件,该文件记录了原始码如何编译的详细信息。编译前的准备工作。

  2. make clean
    读取makefile关于clean的工作。这个步骤不一定会有,但是建议执行一下,因为我们不确定源码里有没有包含上次编译过的目标文件。

  3. make
    make会根据makefile中的预设工作进行编译行为。编译就是进行gcc将源码便以为可执行文件

  4. make install
    将编译好的的数据安装到预定的目录中,完成安装。

2. 案例

安装ntp时间服务器

  1. [root@itcast ~]# tar -zxvf ntp-4.2.8p13.tar.gz
  2. [root@itcast ~]# cd ntp-4.2.8p13/
  3. [root@itcast ntp-4.2.8p13]# ./configure --prefix=/usr/local/ntp //--prefix指出安装目录
  4. [root@itcast ntp-4.2.8p13]# make
  5. [root@itcast ntp-4.2.8p13]# meke install

注意:

  1. # 在执行./configure --prefix=/usr/local/ntp,碰到以下情况,使用后面的指令安装gcc和cc
  2. [root@localhost ntp-4.2.8p13]# ./configure --prefix=/usr/local/ntp
  3. checking for a BSD-compatible install... /usr/bin/install -c
  4. checking whether build environment is sane... yes
  5. checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
  6. checking for gawk... gawk
  7. checking whether make sets $(MAKE)... yes
  8. checking whether make supports nested variables... yes
  9. checking whether make supports nested variables... (cached) yes
  10. checking build system type... x86_64-unknown-linux-gnu
  11. checking host system type... x86_64-unknown-linux-gnu
  12. checking for style of include used by make... GNU
  13. checking for cc... no
  14. checking for gcc... no
  15. configure: error: in `/root/ntp-4.2.8p13':
  16. configure: error: no acceptable C compiler found in $PATH
  17. See `config.log' for more details
  18. # 安装gcc 和 cc
  19. [root@localhost ntp-4.2.8p13]# yum -y install gcc cc