在虚拟机中将cd/dvd连接到系统镜像
执行脚本

##yum.sh
#!bin/bash
mount /dev/cdrom /mnt
cd /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/*
touch /etc/yum.repos.d/local.repo
echo -e "[dvd]\nname=rhel_dvd\nbaseurl=file:///mnt/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/local.repo
yum clean all
yum makecache

也可以使用命令行输入
1、挂载本地镜像

mount /dev/cdrom /mnt

在这里插入图片描述

2、进入yum源配置目录,删除原配置文件,新建本地yum配置文件

##进入yum源配置目录
cd /etc/yum.repos.d/
##删除原配置文件
rm -rf /etc/yum.repos.d/*
##新建本地yum配置文件
touch /etc/yum.repos.d/local.repo
##编辑本地yum配置文件内容
echo -e "[dvd]\nname=rhel_dvd\nbaseurl=file:///mnt/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/local.repo

在这里插入图片描述

也可使用vi编辑器进行编写

vi /etc/yum.repo.d/local.repo
##按下i进入编辑模式
[dvd]
nname=rhel_dvd
baseurl=file:///mnt/
enabled=1
gpgcheck=0

清除yum缓存

yum clean all

在这里插入图片描述

重建yum缓存

yum maskcache

在这里插入图片描述
使用命令测试

yum -y install wget
##或者
yum list

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐