7.1 安装软件包的三种方法
在linux下安装软件包有三种方法:
1、rpm工具 :与Windows的exe安装文件类似,单独安装rpm包,当遇到依赖包时,需要首先安装依赖包,容易遇到多层依赖的情况,安装十分繁琐低效。
2、yum工具 :支持网络在线下载安装,或者本地仓库安装,重点是能够自动搜索安装依赖包,方便高效。
3、源码包安装:下载软件的源代码,在机器上先编译后安装。能够自定义配置安装选项:例如指定安装目录,指定扩展模块等。
7.2 rpm包介绍
要先有rpm包文件,才能用rpm包工具安装:
我们用系统安装光盘里面rpm包来实验
[root@lgs-01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@lgs-01 ~]# ls -l /mnt/Packages/zziplib-0.13.62-5.el7.x86_64.rpm
-rw-rw-r--. 2 root root 83176 7月 4 2014 /mnt/Packages/zziplib-0.13.62-5.el7.x86_64.rpm
[root@lgs-01 ~]# cp /mnt/Packages/zziplib-0.13.62-5.el7.x86_64.rpm /root
[root@lgs-01 ~]# ls -l /root/zziplib-0.13.62-5.el7.x86_64.rpm
-rw-r--r--. 1 root root 83176 4月 18 20:57 /root/zziplib-0.13.62-5.el7.x86_64.rpm
zziplib-0.13.62-5.el7.x86_64.rpm 包:zziplib是包名、0.13.62-5是版本号、el7是发布版本号、x86_64是支持的操作系统平台版本
rmp工具安装:
[root@lgs-01 ~]# rpm -i zziplib-0.13.62-5.el7.x86_64.rpm
[root@lgs-01 ~]# rpm -q zziplib
zziplib-0.13.62-5.el7.x86_64
7.3 rpm工具用法
rpm命令:-ivh 安装rpm包,i 安装、v 可视化过程、h 列出标记
[root@lgs-01 ~]# rpm -ivh /root/zsh-5.0.2-28.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-28.el7 ################################# [100%]
-Uvh:升级rpm包
-e:卸载
[root@lgs-01 ~]# rpm -evh zsh
准备中... ################################# [100%]
正在清理/删除...
1:zsh-5.0.2-28.el7 ################################# [100%]
-qa:显示已安装的rpm包
[root@lgs-01 ~]# rpm -qa
kexec-tools-2.0.14-17.el7.x86_64
setup-2.8.71-7.el7.noarch
NetworkManager-wifi-1.8.0-9.el7.x86_64
bind-license-9.9.4-50.el7.noarch
aic94xx-firmware-30-6.el7.noarch
nss-softokn-freebl-3.28.3-6.el7.x86_64
rsyslog-8.24.0-12.el7.x86_64
ncurses-libs-5.9-13.20130511.el7.x86_64
iprutils-2.4.14.1-1.el7.x86_64
libselinux-2.5-11.el7.x86_64
-q:检查是否已安装该rpm包
[root@lgs-01 ~]# rpm -q zsh
未安装软件包 zsh
[root@lgs-01 ~]# rpm -ivh /root/zsh-5.0.2-28.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-28.el7 ################################# [100%]
[root@lgs-01 ~]# rpm -q zsh
zsh-5.0.2-28.el7.x86_64
-qi:查看包信息
[root@lgs-01 ~]# rpm -qi zsh
Name : zsh
Version : 5.0.2
Release : 28.el7
Architecture: x86_64
Install Date: 2018年04月18日 星期三 21时50分40秒
Group : System Environment/Shells
Size : 5855982
License : MIT
Signature : RSA/SHA256, 2017年08月11日 星期五 04时28分17秒, Key ID 24c6a8a7f4a80eb5
Source RPM : zsh-5.0.2-28.el7.src.rpm
Build Date : 2017年08月02日 星期三 18时52分37秒
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://zsh.sourceforge.net/
Summary : Powerful interactive shell
Description :
The zsh shell is a command interpreter usable as an interactive login
shell and as a shell script command processor. Zsh resembles the ksh
shell (the Korn shell), but includes many enhancements. Zsh supports
command line editing, built-in spelling correction, programmable
command completion, shell functions (with autoloading), a history
mechanism, and more.
-ql:列出包安装了哪些文件
[root@lgs-01 ~]# rpm -ql zip
/usr/bin/zip
/usr/bin/zipcloak
/usr/bin/zipnote
/usr/bin/zipsplit
/usr/share/doc/zip-3.0
/usr/share/doc/zip-3.0/CHANGES
/usr/share/doc/zip-3.0/LICENSE
/usr/share/doc/zip-3.0/README
/usr/share/doc/zip-3.0/README.CR
/usr/share/doc/zip-3.0/TODO
/usr/share/doc/zip-3.0/WHATSNEW
/usr/share/doc/zip-3.0/WHERE
/usr/share/doc/zip-3.0/algorith.txt
/usr/share/man/man1/zip.1.gz
/usr/share/man/man1/zipcloak.1.gz
/usr/share/man/man1/zipnote.1.gz
/usr/share/man/man1/zipsplit.1.g
-qf:查看文件由哪个rpm包安装的
[root@lgs-01 ~]# rpm -qf /usr/bin/ls
coreutils-8.22-18.el7.x86_64
7.4 yum工具用法
yum list:列出可用的安装包(从yum仓库里查找:网络源或者本地源),用grep 可以精准查找想要的包
[root@lgs-01 ~]# yum list |grep libxml2
libxml2.x86_64 2.9.1-6.el7_2.3 @anaconda
libxml2-devel.x86_64 2.9.1-6.el7_2.3 @base
libxml2.i686 2.9.1-6.el7_2.3 base
libxml2-devel.i686 2.9.1-6.el7_2.3 base
libxml2-python.x86_64 2.9.1-6.el7_2.3 base
libxml2-static.i686 2.9.1-6.el7_2.3 base
libxml2-static.x86_64 2.9.1-6.el7_2.3 base
mingw32-libxml2.noarch 2.9.3-1.el7 epel
mingw32-libxml2-static.noarch 2.9.3-1.el7 epel
mingw64-libxml2.noarch 2.9.3-1.el7 epel
mingw64-libxml2-static.noarch 2.9.3-1.el7 epel
yum的仓库配置文件是:/etc/yum.repos.d/CentOS-Base.repo 。
里面的[base] 项下的 mirrorlist= 就是网络源的地址
模糊按包名 搜索包:
[root@lgs-01 ~]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.njupt.edu.cn
* epel: mirror01.idc.hinet.net
* extras: mirrors.njupt.edu.cn
* updates: mirrors.sohu.com
================================================================ N/S matched: vim =================================================================
beakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editor
fluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vim
neovim.x86_64 : Vim-fork focused on extensibility and agility
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
python2-neovim.noarch : Python client to Neovim
python34-neovim.noarch : Python client to Neovim
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-go.x86_64 : Go development plugin for Vim
vim-gtk-syntax.noarch : Vim syntax highlighting for GLib, Gtk+, Gstreamer, and more
vim-jellybeans.noarch : A colorful, dark color scheme for Vim
vim-minimal.x86_64 : A minimal version of the VIM editor
vim-vimoutliner.noarch : Script for building an outline editor on top of Vim
xtuple-csvimp-devel.x86_64 : CSVImp development files
vim-fugitive.noarch : A Git wrapper so awesome, it should be illegal
vim-halibut.noarch : Syntax file for the halibut manual tool
xtuple-csvimp.x86_64 : xTuple data import utility
名称和简介匹配 only,使用“search all”试试。
安装包:
[root@lgs-01 ~]# yum install -y curl
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: ftp.cuhk.edu.hk
* extras: mirrors.njupt.edu.cn
* updates: mirrors.sohu.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 curl.x86_64.0.7.29.0-42.el7 将被 升级
---> 软件包 curl.x86_64.0.7.29.0-42.el7_4.1 将被 更新
--> 正在处理依赖关系 libcurl = 7.29.0-42.el7_4.1,它被软件包 curl-7.29.0-42.el7_4.1.x86_64 需要
--> 正在检查事务
---> 软件包 libcurl.x86_64.0.7.29.0-42.el7 将被 升级
---> 软件包 libcurl.x86_64.0.7.29.0-42.el7_4.1 将被 更新
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================================
正在更新:
curl x86_64 7.29.0-42.el7_4.1 updates 267 k
为依赖而更新:
libcurl x86_64 7.29.0-42.el7_4.1 updates 219 k
事务概要
===================================================================================================================================================
升级 1 软件包 (+1 依赖软件包)
总下载量:486 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): curl-7.29.0-42.el7_4.1.x86_64.rpm | 267 kB 00:00:00
(2/2): libcurl-7.29.0-42.el7_4.1.x86_64.rpm | 219 kB 00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------
总计 819 kB/s | 486 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在更新 : libcurl-7.29.0-42.el7_4.1.x86_64 1/4
正在更新 : curl-7.29.0-42.el7_4.1.x86_64 2/4
清理 : curl-7.29.0-42.el7.x86_64 3/4
清理 : libcurl-7.29.0-42.el7.x86_64 4/4
验证中 : curl-7.29.0-42.el7_4.1.x86_64 1/4
验证中 : libcurl-7.29.0-42.el7_4.1.x86_64 2/4
验证中 : libcurl-7.29.0-42.el7.x86_64 3/4
验证中 : curl-7.29.0-42.el7.x86_64 4/4
更新完毕:
curl.x86_64 0:7.29.0-42.el7_4.1
作为依赖被升级:
libcurl.x86_64 0:7.29.0-42.el7_4.1
完毕!
yum grouplist :列出可用的组套件
[root@lgs-01 ~]# yum grouplist
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: mirror01.idc.hinet.net
* extras: mirrors.cqu.edu.cn
* updates: mirrors.sohu.com
可用的环境分组:
最小安装
基础设施服务器
计算节点
文件及打印服务器
Cinnamon 桌面环境
MATE 桌面环境
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
CIFS 文件服务器
Eclipse
FCoE 存储客户端
Fedora Packager
Haskell
Milkymist
MySQL 数据库客户端
MySQL 数据库服务器
NFS 文件服务器
SNMP 支持
TeX 支持
TurboGears 应用程序构架
Xfce
iSCSI 存储客户端
传统 UNIX 兼容性
兼容性程序库
图形管理工具
基于 Web 的企业管理
存储可用性工具
安全性工具
开发工具
控制台互联网工具
教育软件
智能卡支持
服务器平台
服务器平台开发
桌面
桌面平台
桌面平台开发
电子实验室
科学记数法支持
系统管理
系统管理工具
网络存储服务器
虚拟化
通用桌面
通讯客户端支持
通讯服务器支持
完成
安装组套件:
[root@lgs-01 ~]# yum groupinstall -y 'Xfce'
#节省安装过程
更新完毕:
NetworkManager-libnm.x86_64 1:1.8.0-11.el7_4
作为依赖被升级:
NetworkManager.x86_64 1:1.8.0-11.el7_4 NetworkManager-team.x86_64 1:1.8.0-11.el7_4 NetworkManager-tui.x86_64 1:1.8.0-11.el7_4
NetworkManager-wifi.x86_64 1:1.8.0-11.el7_4 openssh.x86_64 0:7.4p1-13.el7_4 openssh-clients.x86_64 0:7.4p1-13.el7_4
openssh-server.x86_64 0:7.4p1-13.el7_4 python-gobject-base.x86_64 0:3.22.0-1.el7_4.1 systemd.x86_64 0:219-42.el7_4.10
systemd-libs.x86_64 0:219-42.el7_4.10 systemd-sysv.x86_64 0:219-42.el7_4.10
卸载包:
[root@lgs-01 ~]# yum remove -y zsh
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-28.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================================
正在删除:
zsh x86_64 5.0.2-28.el7 installed 5.6 M
事务概要
===================================================================================================================================================
移除 1 软件包
安装大小:5.6 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : zsh-5.0.2-28.el7.x86_64 1/1
验证中 : zsh-5.0.2-28.el7.x86_64 1/1
删除:
zsh.x86_64 0:5.0.2-28.el7
完毕!
升级包:
[root@lgs-01 ~]# yum update -y wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: ftp.cuhk.edu.hk
* extras: mirrors.cqu.edu.cn
* updates: mirrors.sohu.com
No packages marked for update
查看命令需要安装哪个安装包:
[root@lgs-01 ~]# yum provides "/usr/bin/wget"
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: ftp.cuhk.edu.hk
* extras: mirrors.cqu.edu.cn
* updates: mirrors.sohu.com
wget-1.14-15.el7.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
源 :base
匹配来源:
文件名 :/usr/bin/wget
wget-1.14-15.el7_4.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
源 :updates
匹配来源:
文件名 :/usr/bin/wget
wget-1.14-15.el7_4.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
源 :@updates
匹配来源:
文件名 :/usr/bin/wget
7.5 yum搭建本地仓库
当服务器不能访问互联网的时候,我们就需要搭建本地的仓库yum源,使用系统安装碟挂载。
把系统安装光盘挂载到文件系统上:
[root@lgs-01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
备份yum的配置目录以便恢复:
[root@lgs-01 ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
删掉yum配置目录下的所有文件,新建一个yum配置文件:
[root@lgs-01 ~]# rm -rf /etc/yum.repos.d/*
[root@lgs-01 ~]# ls -l /etc/yum.repos.d
总用量 0
创建新的配置文件:
[root@lgs-01 ~]# vim /etc/yum.repos.d/dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0
~
~
~
清楚yum的缓存:
[root@lgs-01 ~]# 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
查看本地yum源仓库:
[root@lgs-01 ~]# yum list
#节省部分
perl-Mozilla-CA.noarch 20130114-5.el7 dvd
perl-Mozilla-LDAP.x86_64 1.5.3-12.el7 dvd
perl-Net-DNS.x86_64 0.72-6.el7 dvd
perl-Net-Daemon.noarch 0.48-5.el7 dvd
perl-Net-HTTP.noarch 6.06-2.el7 dvd
perl-Net-LibIDN.x86_64 0.12-15.el7 dvd
perl-Net-SMTP-SSL.noarch 1.01-13.el7 dvd
perl-Net-SSLeay.x86_64 1.55-6.el7 dvd
perl-NetAddr-IP.x86_64 4.069-3.el7 dvd
perl-Newt.x86_64 1.08-36.el7 dvd
perl-Object-Accessor.noarch 1:0.42-292.el7 dvd
perl-PAR-Dist.noarch 0.49-2.el7 dvd
perl-PCP-PMDA.x86_64 3.11.8-7.el7 dvd
perl-Package-Constants.noarch 1:0.02-292.el7 dvd
perl-Package-DeprecationManager.noarch 0.13-7.el7 dvd
perl-Package-Stash.noarch 0.34-2.el7 dvd
perl-Package-Stash-XS.x86_64 0.26-3.el7 dvd
perl-Params-Check.noarch 1:0.38-2.el7 dvd
perl-Params-Util.x86_64 1.07-6.el7 dvd
perl-Params-Validate.x86_64 1.08-4.el7 dvd
perl-Parse-CPAN-Meta.noarch 1:1.4404-5.el7 dvd
perl-Perl-OSType.noarch 1.003-3.el7 dvd