为什么不能在CentOS 7上安装正确的Node.js新版本?


12

注意:这已部分解决,但需要更多注意。请参阅OP底部的注释以及@Digisec的部分答案。

我正在尝试在CentOS 7上设置Node.js,但以下命令无法安装最新版本。 要在CentOS 7上安装最新版本的Node.js,我需要在下面的代码中进行哪些更改?

我首先输入node --version会导致的结果v0.12.7。显然这是旧版本,因为nodejs.orgv5.6.0是最新的稳定版本。

因此,然后键入以下内容以获取最新版本的node.js:

cd /tmp
curl -sL https://rpm.nodesource.com/setup | bash -

终端打印出我应该键入以下内容以删除过时的node.js版本,因此我键入以下内容:

yum remove -y nodejs npm

终端还说要键入以下内容以安装最新版本的node.js,所以我键入以下内容:

yum install -y nodejs

但是随后我node --version再次键入,终端v0.12.7再次答复,表明前面的命令只是再次重新安装了旧的过时版本。

那么,为了在CentOS 7机器上安装最新的稳定版本的node.js,我需要做什么?


持续的努力:


按照@Digisec的建议,我重新运行了上面的命令,但是这次将所有输出记录到以下文本中。请注意,现在我再次运行它,顺序有所不同,但是结果是一样的,如下所示:

[root@localhost ~]# node --version
v0.12.7
[root@localhost ~]# cd /tmp
[root@localhost tmp]# curl -sL https://rpm.nodesource.com/setup | bash -

## Installing the NodeSource Node.js 0.10 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_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.ePYEdVWXQH' 'https://rpm.nodesource.com/pub_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.ePYEdVWXQH'

## Cleaning up...

+ rm -f '/tmp/tmp.ePYEdVWXQH'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `yum install -y nodejs` (as root) to install Node.js 0.10 and npm.
## You may also need development tools to build native addons:
##   `yum install -y gcc-c++ make`

[root@localhost tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                     Repository                                Size
====================================================================================================================================================================================
Removing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                              @nodesource                               16 M

Transaction Summary
====================================================================================================================================================================================
Remove  1 Package

Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 

Removed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
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:
nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm                                                                                                             | 4.5 MB  00:00:09     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                         1/1 

Installed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[root@localhost tmp]# node --version
v0.12.7
[root@localhost tmp]#   

然后,按照@Digisec的回答,我接下来尝试了以下操作,但是结果仍然无法安装正确的版本,如下面的终端输出所示:

[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.NEM1bxM9WB' '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.NEM1bxM9WB'

## Cleaning up...

+ rm -f '/tmp/tmp.NEM1bxM9WB'

## 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`

[root@localhost tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                             Arch                                Version                                                     Repository                                Size
====================================================================================================================================================================================
Removing:
 nodejs                              x86_64                              0.10.42-1nodesource.el7.centos                              @nodesource                               16 M

Transaction Summary
====================================================================================================================================================================================
Remove  1 Package

Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                             1/1 
  Verifying  : nodejs-0.10.42-1nodesource.el7.centos.x86_64                                                                                                                             1/1 

Removed:
  nodejs.x86_64 0:0.10.42-1nodesource.el7.centos                                                                                                                                    

Complete!
[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
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:
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]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: www.gtlib.gatech.edu
 * epel: mirror.sfo12.us.leaseweb.net
 * extras: dallas.tx.mirror.xygenhosting.com
 * updates: linux.mirrors.es.net
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]# node --version
v0.12.7
[root@localhost tmp]# 

然后,我访问了上面的错误日志所引用的知识库文章,但是发现我无法访问全文,因为我不是Red Had客户。


部分解决方案:


@Digisec通过显示如何安装新版本来部分解决了此问题,但是我们仍然无法删除旧版本,这将有发生冲突的风险。 需要采取什么步骤来删除旧版本,以便新安装可以干净完整地完成?

在此链接中找到了旧版本v0.12.7的tar网址。@Digisec'还建议阅读此链接,建议使用commandmake uninstall我感觉到可能只有五个或十个命令可以在终端中键入以删除旧的v0.12.7并重新安装新版本的nodejs。需要什么命令?

我似乎使用以下终端命令在CentOS 7机器上找到了与nodejs v0.12.7相关的三个tar文件:

[root@localhost ~]# cd /
[root@localhost /]# find . -type f -iname "*.tar"
find: ‘./run/user/1000/gvfs’: Permission denied
./opt/node-v0.12.7/deps/npm/node_modules/tar/test/dir-normalization.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore-2.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore-2.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/node_modules/tar/test/dir-normalization.tar
[root@localhost /]# 

请注意,还有另外三个标记为tar的文件node_modules,它们之间的关系v0.12.7尚不清楚。

我要运行哪些特定命令以安全地从计算机中卸载v0.12.7并删除所有v0.12.7关联的tar文件?


同时发布所有输出也是一个好主意。这将有助于了解正在发生的事情,以便能够更好地为您提供帮助。
Digisec '16

@Digisec我重新运行了命令,然后根据您的要求将完整的输出添加到OP中。我可以做其他事情来帮助解决问题吗?
CodeMed

FWIW,您现在可以使用卸载旧版本的NodeJS yum remove -y nodejs
avazula

Answers:


7

我刚刚检查了您从中获得的链接。具体来说,您正在安装version 0.10,或者至少尝试安装,但是正在安装的存储库中有较新的版本。您必须遵循节点v5的设置。

curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

PS:为了将来参考,请确保您仔细阅读了这些站点,尤其是在以root身份运行命令时。

编辑: 好的,看来您正确添加了仓库。查看仓库,您的软件包在那儿,但是系统正在寻找错误的版本。在这一点上,我建议。

yum clean all && yum update

这将清除缓存的存储库并从远程获取。

答案: 完成工作后chat,这是适合您的正确答案。nodejs v5安装良好。您以前是nodejs v0.12手动编译的,在二进制发行版中这不是一个好主意,因为您最终将处于这个位置。

which node

/usr/local/bin/node

/usr/bin/node

返回的正确答案v5.x

此时,您有多个选项可以修复它,但我建议2。

  • 选项1:这是简单的方法。您可以编辑.bashrc并添加alias指向node -> /usr/bin/node。这就像添加一样简单alias node="/usr/bin/node"。每次都会调用正确的版本,但我不能保证它将来不会与库产生冲突。
  • 选项2:这是很难的方法,但是可以解决。首先,使用yum系统上安装的nodejs进行清除。其次,获取已编译版本的压缩包,解压缩./configure并卸载。这一步,您可以轻松地在线找到。最后,nodejs通过重新安装yum,这应该可以解决您的问题。

感谢您对此进行调查,但这仍不能完全解决问题。请查看我添加到OP末尾的其他终端输出,其中记录了尝试您的建议的结果。我还能尝试什么?
CodeMed

@CodeMed我更新了答案,开始聊天是一个更好的主意。
Digisec '16

那没有解决问题。如果您仍然愿意聊天,我创建了以下聊天室:chat.stackexchange.com/rooms/35670/…–
CodeMed

@CodeMed祝您好运。
Digisec '16

您愿意详细说明选项2吗?还是应该发布一个单独的问题?
CodeMed

4

我做了什么:

rm -f /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_7.x | 重击-
百胜安装-y nodejs
节点-版本

我得到:

v7.2.0

谢谢!这是唯一对我有所帮助的解决方案。
626


1

我尝试从同一NodeSource RepoInstaller安装节点。就我而言,启用nodesource回购解决了问题。更改enabled=0enabled=1,所有方法都应该起作用。

[root@web ~]# cat /etc/yum.repos.d/nodesource-el.repo
[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://rpm.nodesource.com/pub_6.x/el/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL

0

在CentOS 7上安装新版本的npm和nodejs时,我也遇到了一些问题。

我按照nodejs网站上的说明进行操作,然后尝试安装npm。原来是问题所在(npm是从EPEL安装的)。Nodesource存储库不像EPEL那样为npm提供单独的软件包。相反,所有内容都在单个包“ nodejs”中。因此,一旦您从Nodesource安装了nodejs,现在就已经自动安装了npm并准备好进行更新。


0

我在同一个问题上挣扎,也yum clean all没有rm -f /etc/yum.repos.d/nodesource*帮助。然后我发现yum使用了Epel仓库来安装节点,因此我暂时(在/etc/yum.repos.d/epel.reposet中enabled=0)禁用了它,之后

curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install nodejs

0

我也面临同样的问题。

解决方案:1.转到/tmp位置,删除所有文件和文件夹。

cd /tmp
rm -rf *

2.现在您可以使用以下命令来安装NodeJs

curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
sudo yum install -y nodejs
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.