Linux软件包安装与卸载

1、安装软件包的三种方法

  1. rpm工具:Red Hat Package Manager(红帽子公司包管理系统)。一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中。它生成具有.RPM扩展名的文件。与Dpkg类似。与windows的exe类似,安装路径和文件名基本上都是固定好的。

  2. yum工具:是另外一种安装rpm包的工具,操作对象是rpm包,优势是支持自动安装依赖包。

    yum,是Yellow dog Updater Modified的简称,起初是由yellow dog这一发行版的开发者Terra Soft研发,用python写成,那时还叫做yup(yellow dog updater),后经杜克大学的Linux@Duke开发团队进行改进,遂有此名。yum的宗旨是自动化地升级,安装/移除rpm包,收集rpm包的相关信息,检查依赖性并自动提示用户解决。yum的关键之处是要有可靠的repository,顾名思义,这是软件的仓库,它可以是http或ftp站点, 也可以是本地软件池,但必须包含rpm的header, header包括了rpm包的各种信息,包括描述,功能,提供的文件,依赖性等.正是收集了这些 header并加以分析,才能自动化地完成余下的任务。它能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。自己本身也可以做yum服务器,本身可以根据光盘镜像做yum服务器。

  3. 源码包:需要通过编译器把源码包编译成可执行的文件,譬如你拿到ls的源码包你就可以编译成ls命令。

相关概念参考网址:http://www.mamicode.com/info-detail-1852349.html

 

2、rpm包介绍

rpm工具使用

  • 设置光驱并挂载

    把虚拟机右下角的光盘图标连接上,在命令行种挂载光盘。

  • rpm包格式,包名、版本号、发布版本号、平台

    ​ zziplib-0.13.62-5.el7.x86_64.rpm

[root@zyshanlinux-01 d6z]# mount /dev/cdrom /mnt/  ##用mount命令挂载光驱到/mnt/目录下
mount: /dev/sr0 写保护,将以只读方式挂载
[root@zyshanlinux-01 d6z]# cd /mnt/
[root@zyshanlinux-01 mnt]# ls  ##光驱里面的内容,安装系统就用到下面的文件。
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@zyshanlinux-01 mnt]# cd Packages/  ##该目录下有许多rpm包
[root@zyshanlinux-01 Packages]# ls
.
.
.
yum-plugin-versionlock-1.1.31-42.el7.noarch.rpm
yum-utils-1.1.31-42.el7.noarch.rpm
zenity-3.22.0-1.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-28.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm
mount: /dev/sr0 写保护,将以只读方式挂载
[root@zyshanlinux-01 d6z]# cd /mnt/
[root@zyshanlinux-01 mnt]# ls  ##光驱里面的内容,安装系统就用到下面的文件。
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@zyshanlinux-01 mnt]# cd Packages/  ##该目录下有许多rpm包
[root@zyshanlinux-01 Packages]# ls
.
.
.
yum-plugin-versionlock-1.1.31-42.el7.noarch.rpm
yum-utils-1.1.31-42.el7.noarch.rpm
zenity-3.22.0-1.el7.x86_64.rpm
zip-3.0-11.el7.x86_64.rpm
zlib-1.2.7-17.el7.x86_64.rpm
zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-28.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm

 

3、rpm工具用法

  • rpm -ivh rpm包文件名 //安装

zlib-devel-1.2.7-17.el7.x86_64.rpm
zsh-5.0.2-28.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm
##用 -ivh安装rpm包,i是安装,v是可视化,h是人性化的可视化(下面的百分比进度条)
[root@zyshanlinux-01 Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:zsh-5.0.2-28.el7                 ################################# [100%]
zsh-5.0.2-28.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm
##用 -ivh安装rpm包,i是安装,v是可视化,h是人性化的可视化(下面的百分比进度条)
[root@zyshanlinux-01 Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:zsh-5.0.2-28.el7                 ################################# [100%]
##用rpm安装包,会依赖很多的依赖包,要安装A,需要安装B,安装B又需要安装C,很麻烦。
[root@zyshanlinux-01 Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
错误:依赖检测失败:
    texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
错误:依赖检测失败:
    texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
    tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
[root@zyshanlinux-01 Packages]# 
##用yum安装这个包就不需要你去一个个的安装依赖包,共有200多个包全自动安装,非常方便。
[root@zyshanlinux-01 Packages]# yum install texlive
已加载插件:fastestmirror
.
.
.
事务概要
================================================================================================================
安装  1 软件包 (+248 依赖软件包)
升级           (   1 依赖软件包)
​
总下载量:123 M
Is this ok [y/d/N]: n
Exiting on user command
您的事务已保存,请执行:
 yum load-transaction /tmp/yum_save_tx.2018-05-28.10-01.75dIAU.yumtx 重新执行该事务
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# yum install texlive
已加载插件:fastestmirror
.
.
.
事务概要
================================================================================================================
安装  1 软件包 (+248 依赖软件包)
升级           (   1 依赖软件包)
​
总下载量:123 M
Is this ok [y/d/N]: n
Exiting on user command
您的事务已保存,请执行:
 yum load-transaction /tmp/yum_save_tx.2018-05-28.10-01.75dIAU.yumtx 重新执行该事务
[root@zyshanlinux-01 Packages]# 

 

  • rpm -Uvh rpm包文件名 //升级

[root@zyshanlinux-01 Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm^C  ##用U升级包,写入版本号
  • rpm -e 包名 //卸载

[root@zyshanlinux-01 Packages]# rpm -e zsh  ##卸载包成功
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# rpm -e xz  ##卸载失败,需要先卸载其他依赖包先
错误:依赖检测失败:
    xz 被 (已安裝) dracut-033-502.el7.x86_64 需要
    /usr/bin/xz 被 (已安裝) kmod-20-15.el7.x86_64 需要
[root@zyshanlinux-01 Packages]# 
错误:依赖检测失败:
    xz 被 (已安裝) dracut-033-502.el7.x86_64 需要
    /usr/bin/xz 被 (已安裝) kmod-20-15.el7.x86_64 需要
[root@zyshanlinux-01 Packages]# 
  • rpm -qa //查询已安装的包

[root@zyshanlinux-01 Packages]# rpm -qa  ##查询已安装的包
  • rpm -q 包名 //查询指定包是否安装

[root@zyshanlinux-01 Packages]# rpm -q xz
xz-5.2.2-1.el7.x86_64
[root@zyshanlinux-01 Packages]# rpm -q xz1
未安装软件包 xz1 
xz-5.2.2-1.el7.x86_64
[root@zyshanlinux-01 Packages]# rpm -q xz1
未安装软件包 xz1 
  • rpm -qi 包名 //查询指定包信息

[root@zyshanlinux-01 Packages]# rpm -qi vim-enhanced
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 4.el7
Architecture: x86_64
Install Date: 2018年05月22日 星期二 23时19分52秒
Group       : Applications/Editors
Size        : 2296714
License     : Vim
Signature   : RSA/SHA256, 2018年04月25日 星期三 19时50分34秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-4.el7.src.rpm
Build Date  : 2018年04月11日 星期三 07时55分09秒
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.
​
Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package.
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 4.el7
Architecture: x86_64
Install Date: 2018年05月22日 星期二 23时19分52秒
Group       : Applications/Editors
Size        : 2296714
License     : Vim
Signature   : RSA/SHA256, 2018年04月25日 星期三 19时50分34秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-4.el7.src.rpm
Build Date  : 2018年04月11日 星期三 07时55分09秒
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.
​
Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package.
  • rpm -ql 包名 //列出包安装的哪些文件

[root@zyshanlinux-01 Packages]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor
[root@zyshanlinux-01 Packages]# 
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor
[root@zyshanlinux-01 Packages]# 
  • rpm -qf 文件绝对路径 //查看一个文件是由哪个包安装的

[root@zyshanlinux-01 Packages]# rpm -qf /usr/bin/vim  ##查看该文件是由哪个包安装的
vim-enhanced-7.4.160-4.el7.x86_64
##可以用两个反引号包住一个命令,这个命令的输出结果给上一个命令当输入参数用
[root@zyshanlinux-01 Packages]# which ls  ##ls命令有两行,不太适合作为参数
alias ls='ls --color=auto'
    /usr/bin/ls
[root@zyshanlinux-01 Packages]# which cd  ##cd命令可以
/usr/bin/cd
[root@zyshanlinux-01 Packages]# rpm -qf `which cd`  ##代替效果一样的
bash-4.2.46-28.el7.x86_64
[root@zyshanlinux-01 Packages]# 
vim-enhanced-7.4.160-4.el7.x86_64
##可以用两个反引号包住一个命令,这个命令的输出结果给上一个命令当输入参数用
[root@zyshanlinux-01 Packages]# which ls  ##ls命令有两行,不太适合作为参数
alias ls='ls --color=auto'
    /usr/bin/ls
[root@zyshanlinux-01 Packages]# which cd  ##cd命令可以
/usr/bin/cd
[root@zyshanlinux-01 Packages]# rpm -qf `which cd`  ##代替效果一样的
bash-4.2.46-28.el7.x86_64
[root@zyshanlinux-01 Packages]# 

用2个``反引号引住which cd ,即把which cd的输出结果(绝对路径),给rpm -qf作为输入参数,就查到这个文件是哪个包安装的。

 

4、yum工具用法

  • yum list //列出可用rpm包

[root@zyshanlinux-01 Packages]# yum list
##rpm包名和平台            版本号和平台版本         仓库
zziplib.i686              0.13.62-5.el7           base     
zziplib.x86_64            0.13.62-5.el7           base     
zziplib-devel.i686        0.13.62-5.el7           base     
zziplib-devel.x86_64      0.13.62-5.el7           base     
zziplib-utils.x86_64      0.13.62-5.el7           base     
[root@zyshanlinux-01 Packages]# 
##rpm包名和平台            版本号和平台版本         仓库
zziplib.i686              0.13.62-5.el7           base     
zziplib.x86_64            0.13.62-5.el7           base     
zziplib-devel.i686        0.13.62-5.el7           base     
zziplib-devel.x86_64      0.13.62-5.el7           base     
zziplib-utils.x86_64      0.13.62-5.el7           base     
[root@zyshanlinux-01 Packages]# 
  • ls /etc/yum.repos.d/

##仓库的信息
[root@zyshanlinux-01 Packages]# ls /etc/yum.repos.d/  ##yum的配置文件
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@zyshanlinux-01 Packages]# ls /etc/yum.repos.d/CentOS-Base.repo  ##最核心的配置文件
/etc/yum.repos.d/CentOS-Base.repo
[root@zyshanlinux-01 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
​
[base]  ##这个就是仓库名
name=CentOS-$releasever - Base
##这些rpm包都存放在一个容器上,这个容器就是仓库,下面就是仓库的地址
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# ls /etc/yum.repos.d/  ##yum的配置文件
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@zyshanlinux-01 Packages]# ls /etc/yum.repos.d/CentOS-Base.repo  ##最核心的配置文件
/etc/yum.repos.d/CentOS-Base.repo
[root@zyshanlinux-01 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
​
[base]  ##这个就是仓库名
name=CentOS-$releasever - Base
##这些rpm包都存放在一个容器上,这个容器就是仓库,下面就是仓库的地址
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
​
[root@zyshanlinux-01 Packages]# 
  • yum search vim //搜索包

[root@zyshanlinux-01 Packages]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
=============================================== N/S matched: vim ===============================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor
​
  名称和简介匹配 only,使用“search all”试试。
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
=============================================== N/S matched: vim ===============================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor
​
  名称和简介匹配 only,使用“search all”试试。

这种搜索方式不够精准,可以用另外一种方法,就是管道符加过滤

##管道符|是把管道符前面输出的结果作为后面的输入参数,grep则是过滤(指定字符串)
[root@zyshanlinux-01 Packages]# yum list |grep 'vim'
vim-common.x86_64                           2:7.4.160-4.el7            @base    
vim-enhanced.x86_64                         2:7.4.160-4.el7            @base    
vim-filesystem.x86_64                       2:7.4.160-4.el7            @base    
vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-4.el7            base     
vim-minimal.x86_64                          2:7.4.160-4.el7            base     
[root@zyshanlinux-01 Packages]# 
[root@zyshanlinux-01 Packages]# yum list |grep 'vim'
vim-common.x86_64                           2:7.4.160-4.el7            @base    
vim-enhanced.x86_64                         2:7.4.160-4.el7            @base    
vim-filesystem.x86_64                       2:7.4.160-4.el7            @base    
vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-4.el7            base     
vim-minimal.x86_64                          2:7.4.160-4.el7            base     
[root@zyshanlinux-01 Packages]# 
  • yum install [-y] //-y就是不再交互询问

  • yum grouplist [-y] //列出组,安装系统的时候选择的组,组里面包含相应的rpm包

[root@zyshanlinux-01 Packages]# yum grouplist
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Available Environment Groups:
   Minimal Install  ##最小化安装
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Available Environment Groups:
   Minimal Install  ##最小化安装
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

想安装某个组

[root@zyshanlinux-01 Packages]# yum groupinstall 'Virtualization Host'
.
.
.
Install  70 Packages (+186 Dependent packages)
Upgrade   1 Package  (+ 19 Dependent packages)
​
Total download size: 189 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2018-05-28.10-41.DgYga8.yumtx
.
.
.
Install  70 Packages (+186 Dependent packages)
Upgrade   1 Package  (+ 19 Dependent packages)
​
Total download size: 189 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2018-05-28.10-41.DgYga8.yumtx
  • yum remove [-y] //卸载包,非常方便不用一个个去卸载依赖包,但也是一个比较危险的操作。

  • yum update [-y] //升级包,后面必须加包名,否则它会升级所有的包,包括系统等。

  • yum provides "/*/vim" //怎么搜索一个没安装的命令,需要安装的包

[root@zyshanlinux-01 Packages]# yum provides "/*/vim"  ##搜索没安装的包名
[root@zyshanlinux-01 Packages]# rpm -qf `which vim`  ##搜索已安装的包名
[root@zyshanlinux-01 Packages]# rpm -qf `which vim`  ##搜索已安装的包名

 

5、yum搭建本地仓库

yum安装命令需要远程仓库来安装包,如果离线也想用yum安装,那就可以在本地搭载包仓库。

  • 挂载镜像到/mnt目录

  • cp -r /etc/yum.repos.d /etc/yum.repos.d.bak 要对/etc/yum.repos.d目录进行修改前先备份

[root@zyshanlinux-01 Packages]# ls /mnt/
CentOS_BuildTag  EULA  LiveOS    RPM-GPG-KEY-CentOS-7          TRANS.TBL  isolinux
EFI              GPL   Packages  RPM-GPG-KEY-CentOS-Testing-7  images     repodata
[root@zyshanlinux-01 Packages]# cd
[root@zyshanlinux-01 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
CentOS_BuildTag  EULA  LiveOS    RPM-GPG-KEY-CentOS-7          TRANS.TBL  isolinux
EFI              GPL   Packages  RPM-GPG-KEY-CentOS-Testing-7  images     repodata
[root@zyshanlinux-01 Packages]# cd
[root@zyshanlinux-01 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
  • rm -f /etc/yum.repos.d/* 把该目录下的所有(即repo)文件删除

[root@zyshanlinux-01 ~]# cd /etc/yum.repos.d
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@zyshanlinux-01 yum.repos.d]# rm -rf ./*
[root@zyshanlinux-01 yum.repos.d]# ls
[root@zyshanlinux-01 yum.repos.d]# 
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@zyshanlinux-01 yum.repos.d]# rm -rf ./*
[root@zyshanlinux-01 yum.repos.d]# ls
[root@zyshanlinux-01 yum.repos.d]# 
  • vi dvd.repo 新建一个dvd.repo的文件,写入内容如下

[dvd]  ##仓库名
name=install dvd  ##描述字符串
baseurl=file:///mnt  ##包所在的位置
enable=1  ##yum仓库是否可用,1可用,2不可用
gpcheck=0  ##是否检测,作为临时的不用检测
​
name=install dvd  ##描述字符串
baseurl=file:///mnt  ##包所在的位置
enable=1  ##yum仓库是否可用,1可用,2不可用
gpcheck=0  ##是否检测,作为临时的不用检测
​
  • yum clean all 对先前的缓存做一下清除的操作

[root@zyshanlinux-01 yum.repos.d]# yum clean all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@zyshanlinux-01 yum.repos.d]# 
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@zyshanlinux-01 yum.repos.d]# 
  • yum list 查看一下本地仓库的包

.
.
.
zenity.x86_64              3.22.0-1.el7                                 dvd      
zlib-devel.x86_64          1.2.7-17.el7                                 dvd      
zsh.x86_64                 5.0.2-28.el7                                 dvd      
zziplib.x86_64             0.13.62-5.el7                                dvd 
.
.
zenity.x86_64              3.22.0-1.el7                                 dvd      
zlib-devel.x86_64          1.2.7-17.el7                                 dvd      
zsh.x86_64                 5.0.2-28.el7                                 dvd      
zziplib.x86_64             0.13.62-5.el7                                dvd 

yum list |less 可以用Ctrl+f翻屏看,@是已经安装的

tar.x86_64                              2:1.26-32.el7                  @anaconda
tcl.x86_64                              1:8.5.13-8.el7                 @base    
tcp_wrappers-libs.x86_64                7.6-77.el7                     @anaconda
teamd.x86_64                            1.25-5.el7                     @anaconda
Available Packages
389-ds-base.x86_64                      1.3.6.1-16.el7                 dvd      
389-ds-base-libs.x86_64                 1.3.6.1-16.el7                 dvd      
ElectricFence.x86_64                    2.2.2-39.el7                   dvd      
GConf2.x86_64                           3.2.6-8.el7                    dvd      
ImageMagick.x86_64                      6.7.8.9-15.el7_2               dvd   
tcl.x86_64                              1:8.5.13-8.el7                 @base    
tcp_wrappers-libs.x86_64                7.6-77.el7                     @anaconda
teamd.x86_64                            1.25-5.el7                     @anaconda
Available Packages
389-ds-base.x86_64                      1.3.6.1-16.el7                 dvd      
389-ds-base-libs.x86_64                 1.3.6.1-16.el7                 dvd      
ElectricFence.x86_64                    2.2.2-39.el7                   dvd      
GConf2.x86_64                           3.2.6-8.el7                    dvd      
ImageMagick.x86_64                      6.7.8.9-15.el7_2               dvd   

安装一下本地仓库的包,成功

[root@zyshanlinux-01 yum.repos.d]# yum install GConf2
.
.
.
Installed:
  GConf2.x86_64 0:3.2.6-8.el7                                                                                   
​
Dependency Installed:
  psmisc.x86_64 0:22.20-15.el7                                                                                  
​
Complete!
​
.
.
.
Installed:
  GConf2.x86_64 0:3.2.6-8.el7                                                                                   
​
Dependency Installed:
  psmisc.x86_64 0:22.20-15.el7                                                                                  
​
Complete!
​

 

6、yum更换国内源

自带的yum仓库源都是国外的源,速度很慢,所以可以考虑更换国内的源。

  • cd /etc/yum.repos.d/ 跳转到该目录

[root@zyshanlinux-01 yum.repos.d]# ls
dvd.repo
dvd.repo
  • rm -f dvd.repo 把这个文件删除,并把原来的文件还原

[root@zyshanlinux-01 yum.repos.d]# rm -f dvd.repo  ##不要这个文件了
[root@zyshanlinux-01 yum.repos.d]# ls
[root@zyshanlinux-01 yum.repos.d]# cp ../yum.repos.d.bak/* .  ##把备份的文件都还原回来
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@zyshanlinux-01 yum.repos.d]# ls
[root@zyshanlinux-01 yum.repos.d]# cp ../yum.repos.d.bak/* .  ##把备份的文件都还原回来
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo

rm -f CentOS-Base.repo 把国外源给删除了

[root@zyshanlinux-01 yum.repos.d]# rm -f CentOS-Base.repo
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-CR.repo         CentOS-Media.repo    CentOS-Vault.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
##把CentOS-CR.repo删除后,就不能用wget了,只能用curl -O去获取CentOS7-Base-163.repo
[root@zyshanlinux-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base_163.repo
-bash: wget: 未找到命令
[root@zyshanlinux-01 yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0   4643      0 --:--:-- --:--:-- --:--:--  4637
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-CR.repo         CentOS-Media.repo    CentOS-Vault.repo      CentOS7-Base-163.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
[root@zyshanlinux-01 yum.repos.d]# vim CentOS7-Base-163.repo
[root@zyshanlinux-01 yum.repos.d]# 
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-CR.repo         CentOS-Media.repo    CentOS-Vault.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
##把CentOS-CR.repo删除后,就不能用wget了,只能用curl -O去获取CentOS7-Base-163.repo
[root@zyshanlinux-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base_163.repo
-bash: wget: 未找到命令
[root@zyshanlinux-01 yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0   4643      0 --:--:-- --:--:-- --:--:--  4637
[root@zyshanlinux-01 yum.repos.d]# ls
CentOS-CR.repo         CentOS-Media.repo    CentOS-Vault.repo      CentOS7-Base-163.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
[root@zyshanlinux-01 yum.repos.d]# vim CentOS7-Base-163.repo
[root@zyshanlinux-01 yum.repos.d]# 

可以用vim看一下CentOS7-Base-163.repo

yum repolist all 确认国内源确实在仓库列表里

清除缓存,安装国内源里的包

[root@zyshanlinux-01 yum.repos.d]# yum clean all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@zyshanlinux-01 yum.repos.d]# yum install zsh
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror                  ##由于清除了缓存,用yum命令会重新生成缓存
base                                                 | 3.6 kB  00:00:00     
extras                                               | 3.4 kB  00:00:00     
updates                                              | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                        | 166 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                    | 146 kB  00:00:01     
(3/4): base/7/x86_64/primary_db                      | 5.9 MB  00:00:03     
(4/4): updates/7/x86_64/primary_db                   | 2.0 MB  00:00:03 
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@zyshanlinux-01 yum.repos.d]# yum install zsh
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror                  ##由于清除了缓存,用yum命令会重新生成缓存
base                                                 | 3.6 kB  00:00:00     
extras                                               | 3.4 kB  00:00:00     
updates                                              | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                        | 166 kB  00:00:00     
(2/4): extras/7/x86_64/primary_db                    | 146 kB  00:00:01     
(3/4): base/7/x86_64/primary_db                      | 5.9 MB  00:00:03     
(4/4): updates/7/x86_64/primary_db                   | 2.0 MB  00:00:03 

yum install -y wget 换成国内源后,就可以安装wget包

[root@zyshanlinux-01 yum.repos.d]# yum install -y wget


安装wget成功,wget其实就是下载CentOS7-Base-163.repo这个文件

当本地源和网络源同时存在,系统会用网络的源。

 

7、yum下载rpm包

安装扩展源epel

当我们的基础源base的包不够用时,或缺少我们需要的包时,需要安装一个扩展源。叫epel-release

  • yum install -y epel-release 安装后,可以看到多了2个文件,epel.repo是核心文件

[root@zyshanlinux-01 yum.repos.d]# yum install -y epel-release  ##安装扩展源epel-release
.
.
.
[root@zyshanlinux-01 yum.repos.d]# ls  ##安装后多了epel.repo和epel-testing.repo
CentOS-CR.repo         CentOS-Media.repo    CentOS-Vault.repo      CentOS7-Base-163.repo  epel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo  epel-testing.repo
[root@zyshanlinux-01 yum.repos.d]# cat epel.repo  ##可以查看一下扩展源核心文件里的信息
root@zyshanlinux-01 yum.repos.d]# yum list  ##扩展源在基础源的基础上增加了许多包



  • yum list |grep epel 指定筛选epel扩展源的包

[root@zyshanlinux-01 yum.repos.d]# yum list |grep epel


 

yum下载rpm包

它其实是yum的一个插件

  • yum install -y 包名 --downloadonly

[root@zyshanlinux-01 yum.repos.d]# yum install zsh --downloadonly  ##仅下载没安装
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================
 Package              Arch                    Version                       Repository             Size
========================================================================================================
Installing:
 zsh                  x86_64                  5.0.2-28.el7                  base                  2.4 M

Transaction Summary
========================================================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-28.el7.x86_64.rpm                                                      | 2.4 MB  00:00:01     
exiting because "Download Only" specified
[root@zyshanlinux-01 yum.repos.d]# 
[root@zyshanlinux-01 yum.repos.d]# rpm -q zsh  ##确认没安装
package zsh is not installed


  • ls /var/cache/yum/x86_64/7/ 下载下来的zsh放到了这个路径里面了

[root@zyshanlinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/
C7.0.1406-base        C7.1.1503-fasttrack   C7.3.1611-centosplus  centosplus         timedhosts
C7.0.1406-centosplus  C7.1.1503-updates     C7.3.1611-extras      centosplus-source  timedhosts.txt
C7.0.1406-extras      C7.2.1511-base        C7.3.1611-fasttrack   cr                 updates
C7.0.1406-fasttrack   C7.2.1511-centosplus  C7.3.1611-updates     dvd                updates-source
C7.0.1406-updates     C7.2.1511-extras      base                  epel
C7.1.1503-base        C7.2.1511-fasttrack   base-debuginfo        extras
C7.1.1503-centosplus  C7.2.1511-updates     base-source           extras-source
C7.1.1503-extras      C7.3.1611-base        c7-media              fasttrack
[root@zyshanlinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/base
03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2      gen
29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz  packages
cachecookie                                                                              repomd.xml
[root@zyshanlinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/updates/packages
[root@zyshanlinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/updates/packages/
[root@zyshanlinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
zsh-5.0.2-28.el7.x86_64.rpm


老师的视频是在updates,但我这个是下到base里面的packages,要根据实际情况来

  • yum install -y 包名 --downloadonly --downloaddir=路径

##指定路径下载
[root@zyshanlinux-01 yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/

[root@zyshanlinux-01 yum.repos.d]# ls /tmp/  ##确认下载到该目录
1.txt.bz2
1.txt.gz
2.txt.xz
d6z
newdisk
passwd
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-chronyd.service-KkED72
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-vgauthd.service-Zezhni
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-vmtoolsd.service-JLNlEx
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-chronyd.service-cJl5km
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-vgauthd.service-s8rvPC
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-vmtoolsd.service-UtacnT
yum_save_tx.2018-05-28.10-01.75dIAU.yumtx
yum_save_tx.2018-05-28.10-41.DgYga8.yumtx
yum_save_tx.2018-05-28.10-49.cgGoz7.yumtx
yum_save_tx.2018-05-28.11-59.dqCbzc.yumtx
yum_save_tx.2018-05-28.12-08.c3dik_.yumtx
yum_save_tx.2018-05-28.16-44.afb7Ng.yumtx
yum_save_tx.2018-05-28.16-56._KDhor.yumtx
zsh-5.0.2-28.el7.x86_64.rpm



  • yum reinstall -y 包名 --downloadonly --downloaddir=路径

##想把一个已经安装的包下载到本地,会提示已经安装过了
[root@zyshanlinux-01 yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
Package 2:vim-enhanced-7.4.160-4.el7.x86_64 already installed and latest version
Nothing to do


##可以用重新安装的命令,就可以把这个包下载到本地了
[root@zyshanlinux-01 yum.repos.d]# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/

[root@zyshanlinux-01 yum.repos.d]# ls /tmp/
1.txt.bz2
1.txt.gz
2.txt.xz
d6z
newdisk
passwd
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-chronyd.service-KkED72
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-vgauthd.service-Zezhni
systemd-private-4efcd9bf13934eea8a7d9731c7b92cb4-vmtoolsd.service-JLNlEx
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-chronyd.service-cJl5km
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-vgauthd.service-s8rvPC
systemd-private-6c6c5442b41c4a9d9ab30aac1be7abdd-vmtoolsd.service-UtacnT
vim-enhanced-7.4.160-4.el7.x86_64.rpm  ##有了



yumdownloader zsh

也可以下载zsh包,不单zsh包,所有的rpm包都可以,但是是下载在当前目录的。

 

8、源码包安装

先约定:源码包都放到/usr/local/src/,方便找方便管理

[root@zyshanlinux-01 yum.repos.d]# cd
[root@zyshanlinux-01 ~]# cd /usr/local/src/
[root@zyshanlinux-01 src]# ls
[root@zyshanlinux-01 src]# 


下载apache的源码包,在/usr/local/src/下操作就下载到该目录,如果地址失效,可以到r.aminglinux.com 找

[root@zyshanlinux-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
--2018-05-28 17:16:32--  http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9076901 (8.7M) [application/octet-stream]
Saving to: 'httpd-2.4.33.tar.gz'

100%[==============================================================>] 9,076,901   2.48MB/s   in 3.5s   

2018-05-28 17:16:36 (2.48 MB/s) - 'httpd-2.4.33.tar.gz' saved [9076901/9076901]

[root@zyshanlinux-01 src]#
[root@zyshanlinux-01 src]# ls
httpd-2.4.33.tar.gz


解压这个包httpd-2.4.33.tar.gz

[root@zyshanlinux-01 src]# tar -zxvf httpd-2.4.33.tar.gz
[root@zyshanlinux-01 src]# cd httpd-2.4.33
[root@zyshanlinux-01 httpd-2.4.33]# ls
ABOUT_APACHE     INSTALL         NWGNUmakefile     ap.d             docs         libhttpd.dep  support
Apache-apr2.dsw  InstallBin.dsp  README            apache_probes.d  emacs-style  libhttpd.dsp  test
Apache.dsw       LAYOUT          README.cmake      build            httpd.dep    libhttpd.mak
BuildAll.dsp     LICENSE         README.platforms  buildconf        httpd.dsp    modules
BuildBin.dsp     Makefile.in     ROADMAP           config.layout    httpd.mak    os
CHANGES          Makefile.win    VERSIONING        configure        httpd.spec   server
CMakeLists.txt   NOTICE          acinclude.m4      configure.in     include      srclib
[root@zyshanlinux-01 httpd-2.4.33]# 
[root@zyshanlinux-01 src]# cd httpd-2.4.33
[root@zyshanlinux-01 httpd-2.4.33]# ls
ABOUT_APACHE     INSTALL         NWGNUmakefile     ap.d             docs         libhttpd.dep  support
Apache-apr2.dsw  InstallBin.dsp  README            apache_probes.d  emacs-style  libhttpd.dsp  test
Apache.dsw       LAYOUT          README.cmake      build            httpd.dep    libhttpd.mak
BuildAll.dsp     LICENSE         README.platforms  buildconf        httpd.dsp    modules
BuildBin.dsp     Makefile.in     ROADMAP           config.layout    httpd.mak    os
CHANGES          Makefile.win    VERSIONING        configure        httpd.spec   server
CMakeLists.txt   NOTICE          acinclude.m4      configure.in     include      srclib
[root@zyshanlinux-01 httpd-2.4.33]# 

一定要记住跳转到httpd-2.4.33这个目录

[root@zyshanlinux-01 src]# cd httpd-2.4.33

可以查看一下里面的文档信息

[root@zyshanlinux-01 httpd-2.4.33]# more README  ##官方描述
​
[root@zyshanlinux-01 httpd-2.4.33]# more INSTALL  ##安装信息
.
For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html
​
     $ ./configure --prefix=PREFIX  ##具体的安装步骤
     $ make
     $ make install
     $ PREFIX/bin/apachectl start
​
​
[root@zyshanlinux-01 httpd-2.4.33]# more INSTALL  ##安装信息
.
For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html
​
     $ ./configure --prefix=PREFIX  ##具体的安装步骤
     $ make
     $ make install
     $ PREFIX/bin/apachectl start
​

根据上面的安装步骤

引伸出一系列问题:

Apache安装问题:configure: error: APR not found . Please read the documentation

checking for APR... no  
configure: error: APR not found .  Please read the documentation


安装APR,下载所需软件包,如果此时计算机可以上网,执行命令下载文件:

[root@zyshanlinux-01 src]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.gz
[root@zyshanlinux-01 src]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
[root@zyshanlinux-01 src]# wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.bz2


具体解决步骤如下:

1、apr not found问题

[root@zyshanlinux-01 src]# tar -zxvf apr-1.6.3.tar.gz  
[root@zyshanlinux-01 src]# cd apr-1.6.3  
[root@zyshanlinux-01 apr-1.6.3]# ./configure --prefix=/usr/local/apr 
[root@zyshanlinux-01 apr-1.6.3]# make && make install


2、apr-util not found问题

[root@zyshanlinux-01 src]# tar -zxvf apr-util-1.6.1.tar.gz
[root@zyshanlinux-01 src]# cd apr-util-1.6.1
[root@zyshanlinux-01 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@zyshanlinux-01 apr-util-1.6.1]# make && make install


3、pcre问题

[root@zyshanlinux-01 src]# tar -jxvf pcre-8.42.tar.bz2
[root@zyshanlinux-01 src]# cd pcre-8.42
[root@zyshanlinux-01 pcre-8.42]# ./configure --prefix=/usr/local/pcre
[root@zyshanlinux-01 pcre-8.42]# make && make install


最后编译apache时加上:

 --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
 ##有需要可以加上
 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre 


具体操作编译apache:

[root@zyshanlinux-01 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-01 httpd-2.4.33]# make
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-01 httpd-2.4.33]# make install
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-01 httpd-2.4.33]# make
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0
[root@zyshanlinux-01 httpd-2.4.33]# make install
[root@zyshanlinux-01 httpd-2.4.33]# echo $?
0

检测每步操作是否正确用命令,反馈0就是正确的,非0就是有问题的。

echo $?
[root@zyshanlinux-01 httpd-2.4.33]# echo $?  ##检测正确
0


 

编译安装pcre报时报错:

configure: error: C++ compiler cannot create executables


该问题的解决方法:

是因为gcc的组件没有安装完整,执行下面这个命令就可以解决问题

yum install gcc gcc-c++ gcc-g77


 

编译安装apr-util时报错:

fatal error: expat.h: No such file or directory


该问题的解决方法:

一般这类错误都是缺少依赖,执行下面这个命令就可以解决问题,问题是怎么找出来

yum install expat-devel


 

 

  • 卸载就是删除安装的文件

 

 

 

扩展阅读:

  1. yum保留已经安装过的包http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml 

  2. 搭建局域网yum源 http://ask.apelearn.com/question/7627

    搭建一个局域网http的yum源 http://blog.lishiming.net/?p=500

  3. 把源码包打包成rpm包 https://jin-yang.github.io/post/linux-create-rpm-package.html

自我扩展:

linux源码包软件的安装与卸载:

bdbrowser://snapshot/?cache=http%3A%2F%2Fcache.baiducontent.com%2Fc%3Fm%3D9f65cb4a8c8507ed50f089205646cb375802dc7f608096082c94d513c23a0c5c193dbffc6d3f1000d1c57a%26newp%3D8e609a15809301f21dacc33e6014&url=http%3A%2F%2Flib.csdn.net%2Farticle%2Flinux%2F26024

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值