为什么 yum 尝试安装错误版本的 Node.js?

为什么 yum 尝试安装错误版本的 Node.js?

在 CentOS 7 服务器上,我尝试安装5.x的版本Node.js,但由于某种原因,yum不断尝试安装版本并在下载站点0.x找不到版本时返回错误。该错误表明正在将版本文件名与版本url 连接起来。我认为这表明CentOS 7 机器上的 配置有问题。0.x5.xyum0.x5.xyum安装 5.x 版本需要对以下内容进行哪些具体更改?

根错误消息是:

Error downloading packages:
  nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.

可以查看我的下面的代码源自的发布者页面在以下链接。此外,一些并发症可能是由于按照此其他链接中的说明进行的早期尝试。为了探索早期尝试的可能残余,我当前正在运行以下命令并等待结果:grep -rnw '/path/to/somewhere/' -e "pattern"

这是设置节点源位置的终端输出:

[root@localhost tmp]# curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
## Installing the NodeSource Node.js 5.x repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.sH82u4Gpap' 'https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.sH82u4Gpap'
## Cleaning up...
+ rm -f '/tmp/tmp.sH82u4Gpap'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `yum install -y nodejs` (as root) to install Node.js 5.x and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

/tmp以下是执行上述命令后文件夹 内容的列表:

[root@localhost tmp]# ls -al
total 8
drwxrwxrwt. 13 root   root    320 Feb 14 06:13 .
dr-xr-xr-x. 19 root   root   4096 Jan 29 20:54 ..
drwx------.  2 user   user     60 Feb 13 20:05 .esd-1000
drwxrwxrwt.  2 root   root     40 Feb 13 20:04 .font-unix
prw-------.  1 root   root      0 Feb 13 20:05 hogsuspend
drwxrwxrwt.  2 root   root     80 Feb 13 20:05 .ICE-unix
srwxrwxrwx.  1 mongod mongod    0 Feb 13 20:04 mongodb-27017.sock
drwx------.  2 user   user     40 Dec 31  1969 orbit-user
drwx------.  2 user   user     60 Feb 13 20:05 ssh-AmQyH8IIEC2m
drwx------.  3 root   root     60 Feb 13 20:05 systemd-private-74534ca9946043cc88dbe52a38b4344d-colord.service-hDR3Cd
drwx------.  3 root   root     60 Feb 13 20:04 systemd-private-74534ca9946043cc88dbe52a38b4344d-rtkit-daemon.service-ZAQmPk
drwxrwxrwt.  2 root   root     40 Feb 13 20:04 .Test-unix
drwx------.  2 user   user     40 Feb 13 20:08 tracker-extract-files.1000
-r--r--r--.  1 root   root     11 Feb 13 20:05 .X0-lock
drwxrwxrwt.  2 root   root     60 Feb 13 20:05 .X11-unix
drwxrwxrwt.  2 root   root     40 Feb 13 20:04 .XIM-unix

nodejs以下是尝试使用安装的结果yum

[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.lax.hugeserver.com
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: mirror.keystealth.org
 * updates: mirror.supremebytes.com
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================================================================================================================
 Package                            Arch                               Version                                                     Repository                              Size
================================================================================================================================================================================
Installing:
 nodejs                             x86_64                             0.10.42-1nodesource.el7.centos                              nodesource                             4.5 M

Transaction Summary
================================================================================================================================================================================
Install  1 Package

Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
No Presto metadata available for nodesource
nodejs-0.10.42-1nodesource.el7 FAILED                                          
https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found       ]  0.0 B/s |    0 B  --:--:-- ETA 
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/

Error downloading packages:
  nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.
[root@localhost tmp]# 

作为记录,gedit /etc/yum.repos.d/nodesource-el.repo显示以下内容:

[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://rpm.nodesource.com/pub_5.x/el/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL

[nodesource-source]
name=Node.js for Enterprise Linux 7 - $basearch - Source
baseurl=https://rpm.nodesource.com/pub_5.x/el/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
gpgcheck=1  

我怀疑问题可能是由于之前运行了另一个命令造成的:

curl --silent --location rpm.nodesource.com/setup | bash -

我猜测根本的问题是 yum 如何保留这些结果curl --silent --location ... | bash - commands


控制案例:


在不同虚拟机上全新安装的 CentOS 7 上,以下三个简单命令成功安装了正确的当前版本 5.x 的 Nodejs:

# cd /tmp
# curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
# yum install -y nodejs  
# node --version
v5.6.0  

控制案例的这些结果表明问题在于出现问题的机器中 yum 的配置方式。 那么需要对有问题的机器进行哪些具体更改才能配置 yum 生成正确的下载 url? 将所有内容移植到不同的虚拟机上是不合理的。当然,这只是 yum 配置中的一两行,可以通过更改来解决此问题。

答案1

这似乎是缓存问题,但尚不清楚出了什么问题。在聊天中与发帖者进行一番交谈后,运行yum clean all解决了问题。

海报指出了以下内容:

[root@localhost yum]# ls /var/cache/yum/x86_64/7/nodesource/packages 
nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm 
[root@localhost yum]# yum clean all
[root@localhost yum]# ls /var/cache/yum/x86_64/7/nodesource/packages 
[root@localhost yum]# yum install -y nodejs
.... much terminal output during successful install
[root@localhost yum]# node --version
v5.6.0

因此yum clean all删除了缓存中已存储的过时包。

我对基于 Red Hat 的发行版没有足够的知识或经验来说明这里出了什么问题,因此不会进一步发表评论。

答案2

这就是我必须做的......

首先,删除从 EPEL 中安装的 nodejs 包:

sudo yum remove nodejs

列出您的 yum 存储库:

yum repolist

这是我的节点存储库条目的样子:

nodesource/x86_64    Node.js Packages for Enterprise Linux 7 - x86_64

如果您好奇,请列出节点存储库中的包:

yum --disablerepo="*" --enablerepo="nodesource" list available

然后仅使用节点存储库执行 yum install:

yum --disablerepo="*" --enablerepo="nodesource" install nodejs

我怀疑 Node 存储库中使用的编号方案并没有将 Nodejs 提供为 EPEL 存储库中的包的替代品,但这只是一个猜测。

答案3

yum将尝试获取配置的存储库中可用的版本,而不是您想要安装的版本。

安装覆盖官方提供版本的软件包肯定会让你的系统崩溃,而且通常是以微妙的方式。看来你的nodejs存储库正试图做到这一点。更仔细地查看可用的内容、第三方存储库提供的内容以及避免破坏的保护措施。

也许更明智的解决方案是仅为您的帐户安装该软件包,也许直接从源代码安装?

相关内容