rpm工具使用yum工具使用源码包安装yum更换国内源使用系统盘搭建本地仓库源
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rpm工具使用yum工具使用源码包安装yum更换国内源使用系统盘搭建本地仓库源相关的知识,希望对你有一定的参考价值。
Linux安装软件包的三种方法
rpm工具:预先在Linux机器上编译并打包安装的文件,安装迅速。(缺点:安装程序包时,有可能因为依赖另外一个程序包而无法安装)
yum工具:可以使用工具安装时,同时将依赖的另外的程序包同时安装好;(CentOS中免费,Red Hat里需要付费)
源码包:一般源码包都是通过C语言开发出来的,Linux机器必须安装gcc才能编译;
检测命令
echo $?
检查上一条命令是否错误
0为正确 1为错误
RPM工具
rpm包格式:包名、版本号、发布版本号、平台
举例:libjpeg-turbo-devel-1.2.90-5.el7.x86_64.rpm
包名为:libjpeg-turbo-devel
版本号:1.2.90
发布版本号:5.el7
平台:x86_64
准备工作:
光驱设置好系统安装盘镜像,将光驱挂载到/mnt目录下:
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# df -h |grep -v tmpfs
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.5G 27G 6% /
/dev/sda1 197M 97M 100M 50% /boot
/dev/sr0 4.3G 4.3G 0 100% /mnt
[[email protected] ~]# cd /mnt/
[[email protected] 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
[[email protected] mnt]#
安装RPM包
格式:
rpm -ivh [rpm包文件]
[[email protected] Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:zsh-5.0.2-28.el7 ################################# [100%]
[[email protected] Packages]#
升级RPM包
格式:
rpm -Uvh [rpm包文件]
卸载RPM包
格式:
rpm -e [rpm包名]
[[email protected] Packages]# rpm -e zsh
[[email protected] Packages]#
查询
查询安装的包
格式:
rpm -qa
查询指定包是否安装
格式:
rpm -q [包名]
查询指定包信息
格式:
rpm -qi [包名]
列出包安装的文件
格式:
rpm -ql [包名]
[[email protected] 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
[[email protected] Packages]#
列出某个文件属于哪个RPM包
格式:
rpm -qf [文件绝对路径]
[[email protected] Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-2.el7.x86_64
[[email protected] Packages]#
yum工具
yum工具最大的优势就是可以在联网去下载所需要的RPM包,然后自动安装。如果要安装的RPM包邮依赖关系,yum工具会帮我们依次安装所有相关的RPM包;
列出所有RPM包
格式:
yum list
[r[email protected] Packages]# yum list | head -n 10
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
已安装的软件包
GeoIP.x86_64 1.5.0-11.el7 @anaconda
NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libnm.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-team.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-tui.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-wifi.x86_64 1:1.8.0-9.el7 @anaconda
由于管道被破坏而退出
[[email protected] Packages]#
搜索RPM包
格式:
yum search [关键词]
[[email protected] Packages]# yum search vim
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: 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-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-halibut.noarch : Syntax file for the halibut manual tool
xtuple-csvimp.x86_64 : xTuple data import utility
名称和简介匹配 only,使用“search all”试试。
[[email protected] Packages]#
使用管道符搜索
yum list | grep ‘vim‘
[[email protected] 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
beakerlib-vim-syntax.noarch 1.16-3.el7 epel
fluxbox-vim-syntax.noarch 1.3.7-1.el7 epel
neovim.x86_64 0.2.0-2.el7 epel
protobuf-vim.x86_64 2.5.0-8.el7 base
python2-neovim.noarch 0.1.13-3.el7 epel
python34-neovim.noarch 0.1.13-3.el7 epel
vim-X11.x86_64 2:7.4.160-2.el7 base
vim-go.x86_64 1.8-3.el7 epel
vim-gtk-syntax.noarch 20130716-1.el7 epel
vim-halibut.noarch 1.2-1.el7 epel
vim-vimoutliner.noarch 0.3.7-5.el7 epel
xtuple-csvimp.x86_64 0.5.4-8.el7 epel
xtuple-csvimp-devel.x86_64 0.5.4-8.el7 epel
[[email protected] Packages]#
安装RPM包
格式:
yum install [-y] [包名]
[[email protected] Packages]# yum install -y protobuf
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 8.0 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): epel/x86_64/updateinfo | 866 kB 00:00:05
(2/4): epel/x86_64/primary_db | 6.2 MB 00:00:00
(3/4): extras/7/x86_64/primary_db | 145 kB 00:00:05
(4/4): updates/7/x86_64/primary_db | 5.2 MB 00:00:09
Loading mirror speeds from cached hostfile
* epel: mirrors.sohu.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 protobuf.x86_64.0.2.5.0-8.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================
Package 架构 版本 源 大小
==================================================================================================
正在安装:
protobuf x86_64 2.5.0-8.el7 base 338 k
事务概要
==================================================================================================
安装 1 软件包
总下载量:338 k
安装大小:1.1 M
Downloading packages:
protobuf-2.5.0-8.el7.x86_64.rpm | 338 kB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : protobuf-2.5.0-8.el7.x86_64 1/1
验证中 : protobuf-2.5.0-8.el7.x86_64 1/1
已安装:
protobuf.x86_64 0:2.5.0-8.el7
完毕!
[[email protected] Packages]#
卸载RPM包
格式:
yum remove [-y] [RPM包]
升级RPM包
格式:
yum update [-y] [RPM包]
根据命令来查询安装包
格式:
yum provides “[命令]”
yum provides "/*/vim"
搭建yum本地仓库
当系统无法联网时,就无法便捷实用yum工具了,此时我们可以实用光盘系统制作yum源;
挂载镜像到/mnt目录
mount /dev/cdrom /mnt
备份文件
cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
删除文件
[[email protected] Packages]# cd /etc/yum.repos.d
[[email protected] yum.repos.d]# rm -rf ./*
创建新文件
/etc/yum.repos.d/dvd.repo
以及文件内容
[[email protected] yum.repos.d]# vim /etc/yum.repos.d/dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpcheck=0
清除缓存
yum clean all
[[email protected] 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
[[email protected] yum.repos.d]#
刷新生成缓存
yum makecache
[[email protected] yum.repos.d]# yum makecache
已加载插件:fastestmirror
dvd | 3.6 kB 00:00:00
(1/4): dvd/group_gz | 156 kB 00:00:00
(2/4): dvd/filelists_db | 3.1 MB 00:00:00
(3/4): dvd/primary_db | 3.1 MB 00:00:00
(4/4): dvd/other_db | 1.2 MB 00:00:00
Determining fastest mirrors
元数据缓存已建立
[[email protected] yum.repos.d]#
安装软件包
[[email protected] yum.repos.d]# yum install -y tftp
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tftp.x86_64.0.5.2-13.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================
Package 架构 版本 源 大小
==================================================================================================
正在安装:
tftp x86_64 5.2-13.el7 dvd 35 k
事务概要
==================================================================================================
安装 1 软件包
总下载量:35 k
安装大小:48 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : tftp-5.2-13.el7.x86_64 1/1
验证中 : tftp-5.2-13.el7.x86_64 1/1
已安装:
tftp.x86_64 0:5.2-13.el7
完毕!
[[email protected] yum.repos.d]#
更换yum仓库源
yum联网下载源一般都是国外网络资源,我们为了更快安装可以更换为国内的资源下载;
进入目录
cd /etc/yum.repos.d
删除文件
rm -rf CentOS-Base.repo
下载163源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-01-09 01:13:09-- 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
2018-01-09 01:13:15 (108 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])
[[email protected] 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
[[email protected] yum.repos.d]#
或者
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum下载rpm包
有时候我们需要下载RPM包但不安装,仅仅是复制给其他机器使用;
下载RPM包而不安装
默认RPM包保存路径为/var/cache/yum/x86_64/7/base/packages/
格式:
yum install [包名] -y --downloadonly
[[email protected] yum.repos.d]# yum install zsh --downloadonly
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-28.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================
Package 架构 版本 源 大小
==================================================================================================
正在安装:
zsh x86_64 5.0.2-28.el7 base 2.4 M
事务概要
==================================================================================================
安装 1 软件包
总计:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
[[email protected] yum.repos.d]# rpm -q zsh
未安装软件包 zsh
[[email protected] yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
zsh-5.0.2-28.el7.x86_64.rpm
[[email protected] yum.repos.d]#
指定下载RPM包的保存路径
格式:
yum install [包名] --downloadonly --downloaddir=[路径]
[[email protected] yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-28.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================
Package 架构 版本 源 大小
==================================================================================================
正在安装:
zsh x86_64 5.0.2-28.el7 base 2.4 M
事务概要
==================================================================================================
安装 1 软件包
总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
[[email protected] yum.repos.d]# ls /tmp/
1.txt
b
d6z
d6z.tar
systemd-private-29a53244520c4fe384fbfe93dd3912c7-chronyd.service-4xzXLI
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vgauthd.service-G8e3b4
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vmtoolsd.service-w9qRlq
yum_save_tx.2018-01-09.01-34.V0zRaP.yumtx
yum_save_tx.2018-01-09.01-36.aUdoib.yumtx
yum_save_tx.2018-01-09.01-37.eAOZ3u.yumtx
yum_save_tx.2018-01-09.01-43.UDTWTf.yumtx
zsh-5.0.2-28.el7.x86_64.rpm
[[email protected] yum.repos.d]#
下载已安装的RPM包
格式:
yum reinstall -y [包名] --downloadonly --downloaddir=[路径]
[[email protected] yum.repos.d]# yum reinstall vim-enhanced.x86_64 --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 vim-enhanced.x86_64.2.7.4.160-2.el7 将被 已重新安装
--> 解决依赖关系完成
依赖关系解决
==================================================================================================
Package 架构 版本 源 大小
==================================================================================================
重新安装:
vim-enhanced x86_64 2:7.4.160-2.el7 base 1.0 M
事务概要
==================================================================================================
重新安装 1 软件包
总下载量:1.0 M
安装大小:2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-2.el7.x86_64.rpm | 1.0 MB 00:00:06
exiting because "Download Only" specified
[[email protected] yum.repos.d]# ls /tmp/
1.txt
b
d6z
d6z.tar
systemd-private-29a53244520c4fe384fbfe93dd3912c7-chronyd.service-4xzXLI
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vgauthd.service-G8e3b4
systemd-private-29a53244520c4fe384fbfe93dd3912c7-vmtoolsd.service-w9qRlq
vim-enhanced-7.4.160-2.el7.x86_64.rpm
yum_save_tx.2018-01-09.01-34.V0zRaP.yumtx
yum_save_tx.2018-01-09.01-36.aUdoib.yumtx
yum_save_tx.2018-01-09.01-37.eAOZ3u.yumtx
yum_save_tx.2018-01-09.01-43.UDTWTf.yumtx
yum_save_tx.2018-01-09.01-46.58Zlvk.yumtx
zsh-5.0.2-28.el7.x86_64.rpm
[[email protected] yum.repos.d]#
源码包安装
删除目录即可删除源码包;
源码包的编译必须通过GCC编译器,所以必须安装好gcc才能正常安装源码包;
yum install -y gcc
进入下载目录
cd /usr/local/src
下载源码包
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
[[email protected] src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
--2018-01-09 01:51:34-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.178, 2402:f000:1:416:101:6:6:178
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.178|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7684419 (7.3M) [application/octet-stream]
正在保存至: “httpd-2.2.34.tar.gz”
100%[========================================================>] 7,684,419 1.09MB/s 用时 6.8s
2018-01-09 01:51:46 (1.08 MB/s) - 已保存 “httpd-2.2.34.tar.gz” [7684419/7684419])
[[email protected] src]#
解压源码包
tar -zxvf httpd-2.2.34.tar.gz
查看如何安装
more INSTALL
安装方法
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
指定安装路径
./configure --prefix=/usr/local/apache2
编译
make
安装源码包
make install
运行进程
/usr/local/apache2/bin/apachectl start
以上是关于rpm工具使用yum工具使用源码包安装yum更换国内源使用系统盘搭建本地仓库源的主要内容,如果未能解决你的问题,请参考以下文章
7.6 yum更换国内源 7.7 yum下载rpm包 7.8/7.9 源码包安装
5周第2次课 yum更换国内源 yum下载rpm包 源码包安装