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

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

注意:这个问题已部分解决,但需要更多关注。请参阅 OP 底部的注释和@Digisec 的部分答案。

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

我首先输入node --version结果为v0.12.7.这显然是一个旧版本,因为nodejs.org说这v5.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 url 在此链接。 @Digisec' 还建议阅读这个另一个链接,建议使用命令make 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并删除所有关联的 tar 文件?v0.12.7

答案1

我刚刚检查了关联你从那里得到这个。具体来说,您正在安装 version 0.10,或者至少正在尝试安装,但正在安装的存储库中有一个较新的版本。您必须遵循节点 v5 的设置。

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

聚苯乙烯:为了将来的参考,请确保您非常仔细地阅读这些站点,尤其是在运行命令时

编辑: 好吧,看来你添加了回购协议正确。查看存储库,您的软件包在那里,但系统正在寻找错误的版本。在这一点上,我建议。

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进行清除。其次,获取已编译版本的 tarball,解压./configure并卸载它。这一步,你可以发现在线的容易地。最后,nodejs通过重新安装yum,这应该可以解决您的问题。

答案2

我做了什么:

rm -f /etc/yum.repos.d/nodesource-el*
卷曲-sL https://rpm.nodesource.com/setup_7.x |重击-
yum安装-ynodejs
节点--版本

我得到了:

v7.2.0

答案3

CentOS 7.2、NodeJS 6.7.0(https://nodejs.org/download/release/v6.7.0/)。手动安装

wget https://nodejs.org/download/release/v6.7.0/node-v6.7.0.tar.gz
./configure
make
make install

卸载make uninstall

答案4

这里同样的问题。我为解决这个问题所做的是:

所有命令都必须以 root 身份执行,或者至少在每个命令的开头添加 SUDO

卸载nodejs - 在我的例子中是node v8

yum uninstall nodejs npm

从 /etc/yum.repos.d 中删除实际存储库

rm /etc/yum.repos.d/nodesource*

更新您的存储库

yum update

获取更新的存储库 - 在我的例子中为 Node v14

curl -sL https://rpm.nodesource.com/setup_14.x | bash -

我喜欢进行新的 yum 更新(这是可选的)

yum update

安装新版本的节点

yum install nodejs

享受

no code available for this

相关内容