1.问题一:用户权限不够
解决方法一:切换到root用户
(1)切换到root
su -
(2)再执行安装操作
sudo yum install vim
解决方法二:给本用户添加权限
(1)切换到root
su -
(2)编辑 sudoers
文件
visudo
(3)添加用户到 sudoers
文件
root ALL=(ALL) ALL
找到上面这一行内容,并在其下面添加下面添加权限代码
ahpuyjs ALL=(ALL) ALL
(4)退出插入模式
按 Esc 键,此时屏幕左下角的 -- INSERT -- 提示消失,说明已退出插入模式。
(5)保存并退出
输入 :wq ,然后按 Enter 键。
(6)然后关闭终端,再执行安装命令即可
2.问题二:镜像源问题:官方镜像源可能已经失效
问题如下:
[root@localhost ~]# sudo yum install vim
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error" One of the configured repositories failed (Unknown), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable <repoid> or subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true Cannot find a valid baseurl for repo: base/7/x86_64
解决方法:
1. 检查网络连接
确保虚拟机已经正确连接到网络。你可以使用 ping
命令测试网络连通性,例如:
ping www.baidu.com
如果无法 ping 通,可能需要检查虚拟机的网络设置,确保网络适配器配置正确。
2. 检查和配置 DNS
使用公共 DNS 服务器:
vim /etc/resolv.conf
3. 更换镜像源(经常为这个问题)
官方镜像源可能已经失效,你可以更换为国内的镜像源,如阿里云镜像源。
(1)备份原有的 yum
配置文件:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
(2)下载阿里云的 yum
配置文件:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
(3)清理并生成缓存:
yum clean all
yum makecache
(4)再次尝试安装软件:
yum install vim