Linux软件包安装和卸载

7.1 安装软件包的三种方法

rmp工具、  rmp包,不需要设置 安装路径都是固定

 yum  工具:实际操作的是RMP包 ,优势是支持自动安装依赖的包


源码包:可以看到编程语言开发的文件包需要使用编译器编译成可用的包 是三总方法中最难的一总

目录

rpm

语法

选项

yum

语法

选项

参数

 yum搭建本地仓库

 yum更换国内源

yum下载rpm包

yum  在线下载RPM包

源码包安装



 

rpm

是RPM软件包的管理工具。rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎。逐渐受到其他发行版的采用。RPM套件管理方式的出现,让Linux易于安装,升级,间接提升了Linux的适用度。

语法

rpm(选项)(参数)

选项

-a:查询所有套件;
-b<完成阶段><套件档>+或-t <完成阶段><套件档>+:设置包装套件的完成阶段,并指定套件档的文件名称;
-c:只列出组态配置文件,本参数需配合"-l"参数使用;
-d:只列出文本文件,本参数需配合"-l"参数使用;
-e<套件档>或--erase<套件档>:删除指定的套件;
-f<文件>+:查询拥有指定文件的套件;
-h或--hash:套件安装时列出标记;
-i:显示套件的相关信息;
-i<套件档>或--install<套件档>:安装指定的套件档;
-l:显示套件的文件列表;
-p<套件档>+:查询指定的RPM套件档;
-q:使用询问模式,当遇到任何问题时,rpm指令会先询问用户;
-R:显示套件的关联性信息;
-s:显示文件状态,本参数需配合"-l"参数使用;
-U<套件档>或--upgrade<套件档>:升级指定的套件档;
-v:显示指令执行过程;
-vv:详细显示指令执行过程,便于排错。

http://man.linuxde.net/rpm

[root@linux-01 ~]# ls /mnt
[root@linux-01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载

[root@linux-01 mnt]# ls /packages 

 

rpm包格式 :包名  —  主版本号. 次版本 . 小版本(修正) —  发布版本号  —  平台.rpm

使用选项:

安装 -ivh

升级更新 -Uvh

卸载 -e 

卸载时会检测依赖性 有时需要卸载已被依赖的包 

查询已经安装的包  -qa

查询包是否安装  -q

列出安装包的信息  -qi

 

列出安装包所包含的文件

查找文件是由哪个谁安装

不知道命令绝对路径使用反引号查出命令的包名

 

 

 

 

yum

yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。

yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

语法

yum(选项)(参数)

选项

-h:显示帮助信息;
-y:对所有的提问都回答“yes”;
-c:指定配置文件;
-q:安静模式;
-v:详细模式;
-d:设置调试等级(0-10);
-e:设置错误等级(0-10);
-R:设置yum处理一个命令的最大等待时间;
-C:完全从缓存中运行,而不去下载或者更新任何头文件。

参数

install:安装rpm软件包;
update:更新rpm软件包;
check-update:检查是否有可用的更新rpm软件包;
remove:删除指定的rpm软件包;
list:显示软件包的信息;
search:检查软件包的信息;
info:显示指定的rpm软件包的描述信息和概要信息;
clean:清理yum过期的缓存;
shell:进入yum的shell提示符;
resolvedep:显示rpm软件包的依赖关系;
localinstall:安装本地的rpm软件包;
localupdate:显示本地rpm软件包进行更新;
deplist:显示rpm软件包的所有依赖关系。

http://man.linuxde.net/yum

 

list  列出可用的rpm包

 包名                            版本号和平台版本号           仓库名称

zlib-static.x86_64                   1.2.7-18.el7                 base     
zsh.x86_64                              5.0.2-31.el7                 base     
zsh-html.x86_64                      5.0.2-31.el7                base     
zziplib.i686                              0.13.62-9.el7               base     
zziplib.x86_64                         0.13.62-9.el7               base     
zziplib-devel.i686                    0.13.62-9.el7              base     
zziplib-devel.x86_64                0.13.62-9.el7             base     
zziplib-utils.x86_64                  0.13.62-9.el7             base 

 

base 仓库名称


[root@linux-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-CR.repo         CentOS-Media.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo




[root@linux-01 ~]# 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
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

 

 

搜索rpm包

[root@linux-01 ~]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
========================= 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”试试。

精准搜索

   | 管道符

 

安装可用环境分组 

[root@linux-01 ~]# yum grouplist
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.zju.edu.cn
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成

 

卸载  包括卸载依赖的包

 

 yum搭建本地仓库

备份/创建新仓库

 

1、备份
[root@linux-01 mnt]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak    #备份
[root@linux-01 etc]# cd /etc/yum.repos.d/
[root@linux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@linux-01 yum.repos.d]# rm -rf ./*                              #清楚所有源
[root@linux-01 yum.repos.d]# ls





2、新建一个文件 vi dvd.repo

——————输入以下内容————————
 
[dvd]                    #仓库名称
name=install dvd         #名字描述
baseurl=file:///mnt     #仓库位置路径
enable=1                 #仓库是否可用, “0”代表不可用             
gpcheck=0                #是否检测,     “0”代表不检测




3、清除缓存

[root@linux-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: 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@linux-01 yum.repos.d]# yum list    
已安装的软件包
alsa-lib.x86_64                   1.1.4.1-2.el7           @anaconda   #带“@” 代表已安装
alsa-tools-firmware.x86_64        1.1.0-1.el7             @anaconda
apr.x86_64                        1.4.8-3.el7_4.1         @base
可安装的软件包
yum-utils.noarch                  1.1.31-45.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更换国内源

#恢复原仓库源
[root@linux-01 yum.repos.d]# rm -f dvd.repo
[root@linux-01 yum.repos.d]# cp ../yum.repos.d.bak/* .
[root@linux-01 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

#删除核心基本仓库源
[root@linux-01 yum.repos.d]# rm -f CentOS-Base.repo 

#下载国内仓库源
[root@linux-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2019-07-08 21:55:13--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主机 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在连接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo”

100%[==========================================================>] 1,572       --.-K/s 用时 0s      

2019-07-08 21:55:13 (72.1 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])

[root@linux-01 yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo

 

curl 下载国内源

 仓库源地址已换成163的源

试安装 

测试:改仓库名

[root@linux-01 yum.repos.d]# mv CentOS7-Base-163.repo CentOS7-Base-163.repo.123
[root@linux-01 yum.repos.d]# yum repolist all 
[root@linux-01 yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                         源名称                                           状态
C7.0.1406-base/x86_64         CentOS-7.0.1406 - Base                           禁用
C7.0.1406-centosplus/x86_64   CentOS-7.0.1406 - CentOSPlus                     禁用
C7.0.1406-extras/x86_64       CentOS-7.0.1406 - Extras                         禁用
C7.0.1406-fasttrack/x86_64    CentOS-7.0.1406 - CentOSPlus                     禁用


恢复仓库名
[root@linux-01 yum.repos.d]# mv CentOS7-Base-163.repo.123 CentOS7-Base-163.repo
[root@linux-01 yum.repos.d]# yum repolist all
extras/7/x86_64                CentOS-7 - Extras - 163.com                  启用:    419
extras-source/7                CentOS-7 - Extras Sources                    禁用

 

 

 

 

yum下载rpm包

安装扩展源实际是安装一个文件

[root@linux-01 yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  


 

2、1  [root@linux-01 ~]# cd  /etc/yum.repos.d  
2、2  [root@linux-01 yum.repos.d]# yum install -y epel-release
已加载插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink                                                         | 7.2 kB  00:00:00     
 * epel: mirror01.idc.hinet.net
base                                                                         | 3.6 kB  00:00:00     
epel                                                                         | 5.4 kB  00:00:00     
extras                                                                       | 3.4 kB  00:00:00     
updates                                                                      | 3.4 kB  00:00:00     
(1/7): epel/x86_64/group_gz                                                  |  88 kB  00:00:00     
(2/7): extras/7/x86_64/primary_db                                            | 205 kB  00:00:01     
(3/7): base/7/x86_64/group_gz                                                | 166 kB  00:00:09     
(4/7): base/7/x86_64/primary_db                                              | 6.0 MB  00:00:31     
(5/7): updates/7/x86_64/primary_db                                           | 6.5 MB  00:00:30     
(6/7): epel/x86_64/updateinfo                                                | 987 kB  00:01:58     
(7/7): epel/x86_64/primary_db                                                | 6.8 MB  00:04:50     
软件包 epel-release-7-11.noarch 已安装并且是最新版本
无须任何处理



[root@linux-01 yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo



2、3
查看仓库源的地址
[root@linux-01 yum.repos.d]# cat epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch    
failovermethod=priority       #fedora  官方源
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1


2、4
查看仓库源 
[root@linux-01 yum.repos.d]# yum list |grep epel 
zulucrypt-doc.noarch                    5.0.1-1.el7                    epel     
zulucrypt-libs.x86_64                   5.0.1-1.el7                    epel     
zvbi.x86_64                             0.2.35-1.el7                   epel     
zvbi-devel.x86_64                       0.2.35-1.el7                   epel     
zvbi-fonts.noarch                       0.2.35-1.el7                   epel

 

 

 

 

 

yum  在线下载RPM包

遇到喜欢的rpm包可以下载下来保存好

1、下载
[root@linux-01 yum.repos.d]# yum install zsh --downloadonly
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-31.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

====================================================================================================
 Package             架构                   版本                         源                    大小
====================================================================================================
正在安装:
 zsh                 x86_64                 5.0.2-31.el7                 base                 2.4 M

事务概要
====================================================================================================
安装  1 软件包

总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-31.el7.x86_64.rpm                                                  | 2.4 MB  00:00:05     
exiting because "Download Only" specified
[root@linux-01 yum.repos.d]#

默认保存位置  /var/cache/yum/x86_64/7/  ,根据不同的源存在在各自的目录里

[root@linux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
zsh-5.0.2-31.el7.x86_64.rpm

 

 

下载到指定目录

 

[root@linux-01 yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirror01.idc.hinet.net
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-31.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

====================================================================================================
 Package             架构                   版本                         源                    大小
====================================================================================================
正在安装:
 zsh                 x86_64                 5.0.2-31.el7                 base                 2.4 M

事务概要
====================================================================================================
安装  1 软件包

总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified


[root@linux-01 yum.repos.d]# ls /tmp/
1.txt
223
d6z
newdisk
pasdd
systemd-private-275542ef7b7e47c49d9f45dc70e2def5-chronyd.service-96TKSh
t1.zip
tar1.tar
test
yum_save_tx.2019-07-09.22-57.pNMRO1.yumtx
yum_save_tx.2019-07-09.23-04.aAMqIu.yumtx
zsh-5.0.2-31.el7.x86_64.rpm

 如果已安装的rpm包可以使reinstall  重装软件并下载rpm包

[root@linux-01 yum.repos.d]# yum reinstall zsh --downloadonly --downloaddir=/tmp/

源码包安装

 

约定 源码包 下载到 /usr/local/src/

 

 

1.1 下载源码包
  [root@linux-01 src]https://ftp.bit.nl/apache/httpd-2.2.29.tar.gz
1.2 解压
  [root@linux-01 src]tar -zxvf httpd-2.2.29.tar.gz
1.3 查看软件文档
[root@linux-01 httpd-2.2.29]# more README      #介绍Apache的文档

                          Apache HTTP Server

  What is it?
  -----------

  The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
  web server.  Originally designed as a replacement for the NCSA HTTP
  Server, it has grown to be the most popular web server on the
  Internet.  As a project of the Apache Software Foundation, the
  developers aim to collaboratively develop and maintain a robust,
  commercial-grade, standards-based server with freely available
  source code.

  The Latest Version
  ------------------

  Details of the latest version can be found on the Apache HTTP
  server project page under <http://httpd.apache.org/>.

  Documentation
  -------------


[root@linux-01 httpd-2.2.29]# more INSTALL    #Apache安装文档

  APACHE INSTALLATION OVERVIEW

  Quick Start - Unix
  ------------------

  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.2/install.html
      #安装 命令步骤
     $ ./configure --prefix=PREFIX      #指定解压位置       
     $ make
     $ make install
     $ PREFIX/bin/apachectl start

     NOTES: * Replace PREFIX with the filesystem path under which 
              Apache should be installed.  A typical installation
              might use "/usr/local/apache2" for PREFIX (without the
              quotes).

 

2.1
   安装
[root@linux-01 httpd-2.2.29]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu

Configuring Apache Portable Runtime library ...

checking for APR... reconfig
configuring package in srclib/apr now
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.1
checking for chosen layout... apr
checking for gcc... no              ## 错误提示:缺少gcc  使用yum命令gcc
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.29/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure failed for srclib/apr

#安装完gcc后再次执行安装
[root@linux-01 httpd-2.2.29]# ./configure --prefix=/usr/local/apache2
#省略很多内容#
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
[root@linux-01 httpd-2.2.29]# echo $?                # 使用 echo  $?  检查上一步是否正确
0

 

3.1  编译
  [root@linux-01 httpd-2.2.29]#  make
  #省略部分内容#
  libprefork.la os/unix/libos.la -lm /usr/local/src/httpd-2.2.29/srclib/pcre/libpcre.la /usr/local/src/httpd-2.2.29/srclib/apr-util/libaprutil-1.la /usr/local/src/httpd-2.2.29/srclib/apr-util/xml/expat/libexpat.la /usr/local/src/httpd-2.2.29/srclib/apr/libapr-1.la -lrt -lcrypt -lpthread -ldl 
make[1]: 离开目录“/usr/local/src/httpd-2.2.29”
[root@linux-01 httpd-2.2.29]# echo $?
0

3.2 编译安装
     [root@linux-01 httpd-2.2.29]#  make install
  #省略部分内容#
 Installing configuration files
#生成部分目录
 mkdir /usr/local/apache2/conf                                  
 mkdir /usr/local/apache2/conf/extra
 mkdir /usr/local/apache2/conf/original
 mkdir /usr/local/apache2/conf/original/extra
 Installing HTML documents
 mkdir /usr/local/apache2/htdocs
 Installing error documents
 mkdir /usr/local/apache2/error
 Installing icons
 mkdir /usr/local/apache2/icons
mkdir /usr/local/apache2/logs
Installing CGIs
mkdir /usr/local/apache2/cgi-bin
Installing header files
Installing build system files
Installing man pages and online manual
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: 离开目录“/usr/local/src/httpd-2.2.29”
 [root@linux-01 httpd-2.2.29]# echo $?
0

 

查看生成的目录

[root@linux-01 httpd-2.2.29]# ls /usr/local/apache2/
bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

 

 

源码包 要去可信任的网站下载

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值