CentOS中yum安装软件时报错:No package XXX available

时间:2021-07-31 14:23:02

yum 安装软件时,报错:No package XXX available.

[root@localhost ~]# yum -y install redis
Loaded plugins: fastestmirror
No package redis available.
Nothing to do

配置一台CentOS 7.x或RHEL 7.x的系统使用Fedora EPEL  repos和第三方软件包安装各种软件包。请注意,这些软件包没有正式获得任何的CentOS或Red Hat的支持,但提供了许多流行的包和应用程序。

显示以上错误,有以下2种原因:

1、dns问题;

2、镜像连接错误;

DNS问题

首先测试下网络连接,如果ping不通,需要设置下DNS。

[root@localhost ~]# ping www.baidu.com
XXXXXXXXXXXXXXXXX
[root@localhost ~]# echo "nameserver 8.8.8.8">>/etc/resolv.conf

再次ping即可ping通了。

镜像连接错误问题

具体原因:使用yum搜索某些rpm包,找不到包是因为CentOS是RedHat企业版编译过来的,去掉了所有关于版权问题的东西。安装EPEL后可以很好的解决这个问题。EPEL(Extra Packages for Enterprise Linux )即企业版Linux的扩展包,提供了很多可共Centos使用的组件,安装完这个以后基本常用的rpm都可以找到。

Method #1 » 从企业版Linux库配置包中安装扩展包。(推荐 )

[root@localhost ~]# sudo yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-5 will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
epel-release noarch 7-5 extras 14 k Transaction Summary
================================================================================
Install 1 Package Total download size: 14 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-5.noarch.rpm | 14 kB 00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-5.noarch 1/1
Verifying : epel-release-7-5.noarch 1/1 Installed:
epel-release.noarch 0:7-5 Complete!

Method #2 » 从dl.fedoraproject.org安装扩展包。

1.使用wget命令下载epel-release:

[root@localhost ~]# cd/tmp
[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ls*.rpm

或者通过wiki查找到对应版本的epel后,再下载:

[root@localhost ~]# wget http://dl.fedoraproject.org/pub/epel/7/x86_64/epel-release-7-5.noarch.rpm

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/fedora/epel/7/x86_64/epel-release-7-5.noarch.rpm //中国科学技术大学镜像

2.安装:

[root@localhost ~]# sudo yum install epel-release-7.noarch.rpm

注意:

1. epel的版本要与centos的版本相对应,否则安装失败,即centos7版本要对应epel7版本。

2. rpm安装完后,rpm -ql  epel*,确提示未安装,此时要导入rpm的签名信息

#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 (root身份执行)