当我尝试安装 NGINX 时出现错误

NGINX is giving error when i try to install

我正在尝试安装 nginx 亚马逊 Linux AMI

但是当我尝试 运行 命令时

sudo yum install nginx

错误如下

Loaded plugins: langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 0:1.14.0-1.el6.ngx will be installed
--> Processing Dependency: libpcre.so.0()(64bit) for package: nginx-1.14.0-1.el6.ngx.x86_64
--> Finished Dependency Resolution
Error: Package: nginx-1.14.0-1.el6.ngx.x86_64 (nginx)
           Requires: libpcre.so.0()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

首先 运行 $ sudo yum update -y 然后尝试安装,如果仍然遇到同样的问题然后尝试 $ sudo yum install nginx --skip-broken

我遇到了完全相同的问题。检查你是否有像 /etc/yum.repos.d/nginx.repo.

这样的文件

Nginx install instructions 告诉我们创建这样一个文件,它应该如下所示:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

这些说明也告诉我们

Due to differences between how CentOS, RHEL, and Scientific Linux populate the $releasever variable, it is necessary to manually replace $releasever with either 5 (for 5.x) or 6 (for 6.x), depending upon your OS version.

因此您需要将 $releasever 替换为您的 OS 的适当版本。但是当使用 Amazon Linux AMI(或者,在我的例子中是 Azure 版本)时,很难分辨这是什么。

我发现 sudo yum install nginx 仅在我将 $releasever 替换为 7 时有效。 当我使用 6 时,我和你一样得到了确切的错误。希望这对您有所帮助!