No package nginx available.Error: Nothing to do

在 CentOS 系统中,nginx 包默认不在官方的 YUM 仓库中,因此直接使用 yum install nginx 可能会提示找不到包。要解决这个问题,你需要添加包含 nginx 的第三方仓库,或者手动安装 nginx

以下是两种常见的解决方法:

方法 1:添加 Nginx 官方仓库

  1. 安装 EPEL 仓库
    EPEL(Extra Packages for Enterprise Linux)仓库包含了许多额外的软件包,包括 nginx

    yum install epel-release

  2. 安装 Nginx
    安装 EPEL 仓库后,再次尝试安装 nginx

    yum install nginx
  3. 启动 Nginx
    安装完成后,启动并启用 Nginx 服务:

    systemctl start nginx
    systemctl enable nginx
  4. 验证安装
    打开浏览器,访问服务器的 IP 地址,如果看到 Nginx 的欢迎页面,说明安装成功。


方法 2:手动添加 Nginx 官方仓库

如果你希望使用 Nginx 官方提供的最新版本,可以手动添加 Nginx 的官方仓库。

  1. 创建 Nginx 仓库文件
    在 /etc/yum.repos.d/ 目录下创建一个新的仓库文件:

    vi /etc/yum.repos.d/nginx.repo
  2. 添加以下内容
    将以下内容粘贴到文件中:

    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    
    [nginx-mainline]
    name=nginx mainline repo
    baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true
    • nginx-stable 是稳定版仓库。

    • nginx-mainline 是主线版仓库(默认禁用,如果需要可以启用)。

  3. 安装 Nginx
    保存并退出后,运行以下命令安装 nginx

    yum install nginx
  4. 启动 Nginx
    启动并启用 Nginx 服务:

    systemctl start nginx
    systemctl enable nginx
  5. 验证安装
    打开浏览器,访问服务器的 IP 地址,如果看到 Nginx 的欢迎页面,说明安装成功。


总结

  • 如果你只需要稳定版本的 Nginx,推荐使用 方法 1(安装 EPEL 仓库)。

  • 如果你需要最新版本的 Nginx,可以使用 方法 2(手动添加 Nginx 官方仓库)。

根据你的需求选择合适的方法即可解决问题。

[root@iZbp11irq8z6b1plo30y63Z ~]# sudo yum install epel-release -y Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 4.3 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 Package epel-release-7-14.noarch already installed and latest version Nothing to do [root@iZbp11irq8z6b1plo30y63Z ~]# sudo yum install nginx -y Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile No package nginx available. Error: Nothing to do [root@iZbp11irq8z6b1plo30y63Z ~]# sudo yum install gcc make pcre-devel zlib-devel openssl-devel -y Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Loading mirror speeds from cached hostfile Package gcc-4.8.5-44.el7.x86_64 already installed and latest version Package 1:make-3.82-24.el7.x86_64 already installed and latest version Package pcre-devel-8.32-17.el7.x86_64 already installed and latest version Package zlib-devel-1.2.7-21.el7_9.x86_64 already installed and latest version Package 1:openssl-devel-1.0.2k-26.el7_9.x86_64 already installed and latest version Nothing to do [root@iZbp11irq8z6b1plo30y63Z ~]#
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一路生花工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值