安装软件包的三种方法:
·rpm工具
·yum工具
·源码包
难度:源码包 > rpm工具 > yum工具
7.2 rpm包介绍
·rpm工具使用
设置光驱并挂载
在虚拟机光盘位置,设置光盘连接后,进入系统中挂载光驱
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda3 18G 1.2G 17G 7% / devtmpfs 479M 0 479M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.7M 482M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/sdb 10G 33M 10G 1% /mnt /dev/sda1 197M 97M 100M 50% /boot tmpfs 98M 0 98M 0% /run/user/0 ##mnt目录并未挂载,可以将光盘挂载于此 [root@localhost ~]# mount /dev/cdrom /mnt mount: /dev/sr0 写保护,将以只读方式挂载 [root@localhost ~]# cd /mnt/ [root@localhost mnt]# ls ##Packages中存有许多rpm包 CentOS_BuildTag EFI EULA GPL images isolinux LiveOS Packages repodata RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Testing-7 TRANS.TBL [root@localhost mnt]# ls Packages/ 文件过多,例举部分 tdb-tools-1.3.12-2.el7.x86_64.rpm
·rpm包格式:包名、版本号、发布版本号、平台
tdb-tools-1.3.12-2.el7.x86_64.rpm
包名:tdb-tools
版本号:1.3.12
发布版本号:2.el7 ##7是CentOS7,如果是6就是CentOS6
平台:x86_64 ##CentOS7之后只有64位
7.3 rpm工具用法
·安装rpm包:rpm -ivh rpm包文件 (i安装,v可视化,h人性化)
例如安装zsh-5.0.2-28.el7.x86_64.rpm
[root@localhost mnt]# cd Packages/ ##cd到Packages下更方便 [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:zsh-5.0.2-28.el7 ################################# [100%]
·升级rpm包:rpm -Uvh rpm包文件 (U升级,v可视化,h人性化)
[root@localhost Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm
·卸载包:rpm -e 包名
[root@localhost Packages]# rpm -e zsh
(卸载包,可能会出现各种依赖关系,要依次卸载)
·查询安装的包:rpm -qa
[root@localhost Packages]# rpm -qa open-vm-tools-10.1.5-3.el7.x86_64 grub2-common-2.02-0.64.el7.centos.noarch 文件过多,不详细列出
·查询指定包是否安装:rpm -q 包名
[root@localhost Packages]# rpm -q zsh 未安装软件包 zsh [root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm 准备中... ################################# [100%] 正在升级/安装... 1:zsh-5.0.2-28.el7 ################################# [100%] [root@localhost Packages]# rpm -q zsh zsh-5.0.2-28.el7.x86_64
·查询指定包信息:rpm -qi (i信息info)
[root@localhost Packages]# rpm -qi vim-enhanced Name : vim-enhanced Epoch : 2 Version : 7.4.160 Release : 2.el7 Architecture: x86_64 Install Date: 2017年12月31日 星期日 20时43分20秒 Group : Applications/Editors Size : 2292098 License : Vim Signature : RSA/SHA256, 2017年08月11日 星期五 04时15分38秒, Key ID 24c6a8a7f4a80eb5 Source RPM : vim-7.4.160-2.el7.src.rpm Build Date : 2017年08月02日 星期三 08时46分12秒 Build Host : c1bm.rdu2.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@localhost 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
·查看一个文件时有哪个包安装的:rpm -qf 文件绝对路径 (q询问query,f文件file)
[root@localhost Packages]# rpm -qf /usr/bin/vim vim-enhanced-7.4.160-2.el7.x86_64 [root@localhost Packages]# rpm -qf `which cd` ##如果不知道命令的绝对路径,那么可以利用which命令和反引号 ` bash-4.2.46-28.el7.x86_64
7.4 yum工具用法
安装rpm包时,很可能需要解决依赖关系,不是很方便,那么使用yum安装就很方便了
[root@localhost 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 需要
yum可以自动解决依赖关系,可以帮助自动安装好
[root@localhost Packages]# yum install texlive
·列出可用的rpm包:yum list
[root@localhost Packages]# yum list
·yum配置文件:/etc/yum.repos.d/
[root@localhost Packages]# ls /etc/yum.repos.d/ CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
·搜索相关包:yum search 关键字
[root@localhost Packages]# yum search vim 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.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”试试。
·精准搜索包:yum list |grep '关键字'
[root@localhost Packages]# yum list |grep 'vim' vim-common.x86_64 2:7.4.160-2.el7 @base vim-enhanced.x86_64 2:7.4.160-2.el7 @base vim-filesystem.x86_64 2:7.4.160-2.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-2.el7 base
·自动安装:yum install [-y]
[root@localhost Packages]# yum install vim [root@localhost Packages]# yum install vim -y
·查看可用的组:yum grouplist
[root@localhost Packages]# yum grouplist 已加载插件:fastestmirror 没有安装组信息文件 Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.163.com 可用的环境分组: 最小安装 基础设施服务器 计算节点 文件及打印服务器 基本网页服务器 虚拟化主机 带 GUI 的服务器 GNOME 桌面 KDE Plasma Workspaces 开发及生成工作站 可用组: 传统 UNIX 兼容性 兼容性程序库 图形管理工具 安全性工具 开发工具 控制台互联网工具 智能卡支持 科学记数法支持 系统管理 系统管理工具完成
(安装系统时,我们选择的时最小安装)
·安装组:yum groupinstall 组名
[root@localhost ~]#LANG=en ##系统语言为中文,安装时改成英文,中文为 zh_CN.UTF-8 [root@localhost ~]# 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.aliyun.com * extras: mirrors.aliyun.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@localhost ~]# yum groupinstall 'Virtualization Host' ##如果安装的组名称不是一个单词,要加上引号
可以看出,有65包需要安装,还有184个被依赖的,6个要升级的
·卸载包:yum remove [ -y ]
[root@localhost ~]# yum remove ppp
yum remove可以同时列出依赖的包,并同时卸载
·升级包:yum update [ -y ] 包名 ##如果不加包名,会把系统所有rpm包升级,甚至是系统、内核
·搜索一个命令用哪一个包:yum provides “/*/命令" ##命令没有安装的话,可以用
7.5 yum搭建本地仓库
如果不能联网,搭建本地yum仓库将非常方便
·挂载镜像到 /mnt 目录
[root@localhost ~]# mount /dev/cdrom /mnt
·制作本地仓库:
[root@localhost ~]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak ##备份yum仓库 [root@localhost ~]# cd /etc/yum.repos.d [root@localhost yum.repos.d]# ls CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo [root@localhost yum.repos.d]# rm -rf *.repo ##删除所有yum源(之前已做备份) [root@localhost yum.repos.d]# ls [root@localhost yum.repos.d]# vim dvd.repo##编辑新的yum源 [dvd] name=install dvd baseurl=file:///mnt enable=1 gpgcheck=0
完成后保存退出
[root@localhost yum.repos.d]# yum clean all ##清除缓存 已加载插件:fastestmirror File contains no section headers. file: file:///etc/yum.repos.d/dvd.repo, line: 1 'me=install dvd\n'
[root@localhost yum.repos.d]# yum list |less ##查看可以安装的包
[root@localhost yum.repos.d]# yum install GConf2 ##任选其中一个进行安装,现在的源是dvd
原文:http://blog.51cto.com/11530642/2058571