在 Centos 上安装 Nodejs 时出现问题(使用 yum 并从源代码构建)

在 Centos 上安装 Nodejs 时出现问题(使用 yum 并从源代码构建)

我正在尝试在 CentOS 上安装最新的 Nodejs:

[root@test-visitele ~]# uname -a
Linux test-visitele 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@test-visitele ~]# sudo yum install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.alpha-labs.net
 * epel: ftp.plusline.net
 * extras: mirror.23media.com
 * updates: mirror.23media.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be updated
---> Package epel-release.noarch 0:7-12 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
 Package                   Arch                Version           Repository         Size
=========================================================================================
Updating:
 epel-release              noarch              7-12              epel               15 k

Transaction Summary
=========================================================================================
Upgrade  1 Package

Total download size: 15 k
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
epel-release-7-12.noarch.rpm                                      |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Updating   : epel-release-7-12.noarch                                              1/2 
  Cleanup    : epel-release-7-11.noarch                                              2/2 
  Verifying  : epel-release-7-12.noarch                                              1/2 
  Verifying  : epel-release-7-11.noarch                                              2/2 

Updated:
  epel-release.noarch 0:7-12                                                             

Complete!
[root@test-visitele ~]# sudo yum install nodejs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centosmirror.netcup.net
 * epel: ftp.plusline.net
 * extras: mirror.23media.com
 * updates: mirror.23media.com
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 1:6.17.1-1.el7 will be updated
--> Processing Dependency: nodejs = 1:6.17.1-1.el7 for package: 1:npm-3.10.10-1.6.17.1.1.el7.x86_64
---> Package nodejs.x86_64 2:10.20.1-1nodesource will be an update
--> Finished Dependency Resolution
Error: Package: 1:npm-3.10.10-1.6.17.1.1.el7.x86_64 (@epel)
           Requires: nodejs = 1:6.17.1-1.el7
           Removing: 1:nodejs-6.17.1-1.el7.x86_64 (@epel)
               nodejs = 1:6.17.1-1.el7
           Updated By: 2:nodejs-10.20.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.20.1-1nodesource
           Available: 2:nodejs-10.0.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.0.0-1nodesource
           Available: 2:nodejs-10.1.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.1.0-1nodesource
           Available: 2:nodejs-10.2.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.2.1-1nodesource
           Available: 2:nodejs-10.3.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.3.0-1nodesource
           Available: 2:nodejs-10.4.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.4.0-1nodesource
           Available: 2:nodejs-10.4.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.4.1-1nodesource
           Available: 2:nodejs-10.5.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.5.0-1nodesource
           Available: 2:nodejs-10.6.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.6.0-1nodesource
           Available: 2:nodejs-10.7.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.7.0-1nodesource
           Available: 2:nodejs-10.8.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.8.0-1nodesource
           Available: 2:nodejs-10.9.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.9.0-1nodesource
           Available: 2:nodejs-10.10.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.10.0-1nodesource
           Available: 2:nodejs-10.11.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.11.0-1nodesource
           Available: 2:nodejs-10.12.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.12.0-1nodesource
           Available: 2:nodejs-10.13.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.13.0-1nodesource
           Available: 2:nodejs-10.14.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.14.1-1nodesource
           Available: 2:nodejs-10.14.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.14.2-1nodesource
           Available: 2:nodejs-10.15.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.0-1nodesource
           Available: 2:nodejs-10.15.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.1-1nodesource
           Available: 2:nodejs-10.15.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.2-1nodesource
           Available: 2:nodejs-10.15.3-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.3-1nodesource
           Available: 2:nodejs-10.16.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.0-1nodesource
           Available: 2:nodejs-10.16.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.1-1nodesource
           Available: 2:nodejs-10.16.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.2-1nodesource
           Available: 2:nodejs-10.16.3-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.3-1nodesource
           Available: 2:nodejs-10.17.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.17.0-1nodesource
           Available: 2:nodejs-10.18.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.18.0-1nodesource
           Available: 2:nodejs-10.18.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.18.1-1nodesource
           Available: 2:nodejs-10.19.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.19.0-1nodesource
           Available: 2:nodejs-10.20.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.20.0-1nodesource
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

我究竟做错了什么?我该如何修复它? (我正在尝试遵循此说明在此输入链接描述

更新: 尝试更新 npm 没有任何结果

# yum install nodejs npm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centosmirror.netcup.net
 * epel: ftp.plusline.net
 * extras: mirror.23media.com
 * updates: mirror.23media.com
digitalocean-agent                                                | 3.3 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 2:10.20.1-1nodesource will be installed
---> Package npm.x86_64 1:3.10.10-1.6.17.1.1.el7 will be installed
--> Processing Dependency: nodejs = 1:6.17.1-1.el7 for package: 1:npm-3.10.10-1.6.17.1.1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: 1:npm-3.10.10-1.6.17.1.1.el7.x86_64 (epel)
           Requires: nodejs = 1:6.17.1-1.el7
           Available: 1:nodejs-6.17.1-1.el7.x86_64 (epel)
               nodejs = 1:6.17.1-1.el7
           Available: 2:nodejs-10.0.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.0.0-1nodesource
           Available: 2:nodejs-10.1.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.1.0-1nodesource
           Available: 2:nodejs-10.2.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.2.1-1nodesource
           Available: 2:nodejs-10.3.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.3.0-1nodesource
           Available: 2:nodejs-10.4.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.4.0-1nodesource
           Available: 2:nodejs-10.4.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.4.1-1nodesource
           Available: 2:nodejs-10.5.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.5.0-1nodesource
           Available: 2:nodejs-10.6.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.6.0-1nodesource
           Available: 2:nodejs-10.7.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.7.0-1nodesource
           Available: 2:nodejs-10.8.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.8.0-1nodesource
           Available: 2:nodejs-10.9.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.9.0-1nodesource
           Available: 2:nodejs-10.10.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.10.0-1nodesource
           Available: 2:nodejs-10.11.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.11.0-1nodesource
           Available: 2:nodejs-10.12.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.12.0-1nodesource
           Available: 2:nodejs-10.13.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.13.0-1nodesource
           Available: 2:nodejs-10.14.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.14.1-1nodesource
           Available: 2:nodejs-10.14.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.14.2-1nodesource
           Available: 2:nodejs-10.15.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.0-1nodesource
           Available: 2:nodejs-10.15.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.1-1nodesource
           Available: 2:nodejs-10.15.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.2-1nodesource
           Available: 2:nodejs-10.15.3-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.15.3-1nodesource
           Available: 2:nodejs-10.16.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.0-1nodesource
           Available: 2:nodejs-10.16.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.1-1nodesource
           Available: 2:nodejs-10.16.2-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.2-1nodesource
           Available: 2:nodejs-10.16.3-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.16.3-1nodesource
           Available: 2:nodejs-10.17.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.17.0-1nodesource
           Available: 2:nodejs-10.18.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.18.0-1nodesource
           Available: 2:nodejs-10.18.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.18.1-1nodesource
           Available: 2:nodejs-10.19.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.19.0-1nodesource
           Available: 2:nodejs-10.20.0-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.20.0-1nodesource
           Installing: 2:nodejs-10.20.1-1nodesource.x86_64 (nodesource)
               nodejs = 2:10.20.1-1nodesource
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

尝试从源代码构建,但无法编译:

[root@test-visitele node-v12.16.3]# make
make -C out BUILDTYPE=Release V=0
...

In file included from ../src/env-inl.h:27:0,
                 from ../src/api/async_resource.cc:2:
../src/aliased_buffer.h:32:22: error: expected type-specifier
           typename = std::enable_if_t<std::is_scalar<NativeT>::value>>
                      ^
../src/aliased_buffer.h:32:22: error: expected ‘>’
../src/aliased_buffer.h:65:54: error: template argument 3 is invalid
       const AliasedBufferBase<uint8_t, v8::Uint8Array>& backing_buffer)
                                                      ^
../src/aliased_buffer.h:112:45: error: template argument 3 is invalid
     Reference(AliasedBufferBase<NativeT, V8T>* aliased_buffer, size_t index)
                                             ^
../src/aliased_buffer.h:150:35: error: template argument 3 is invalid
     AliasedBufferBase<NativeT, V8T>* aliased_buffer_;
                                   ^
../src/aliased_buffer.h: In constructor ‘node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::AliasedBufferBase(v8::Isolate*, size_t, size_t, const int&)’:
../src/aliased_buffer.h:69:52: error: request for member ‘GetArrayBuffer’ in ‘backing_buffer’, which is of non-class type ‘const int’
     v8::Local<v8::ArrayBuffer> ab = backing_buffer.GetArrayBuffer();
                                                    ^
../src/aliased_buffer.h:78:45: error: request for member ‘GetNativeBuffer’ in ‘backing_buffer’, which is of non-class type ‘const int’
         const_cast<uint8_t*>(backing_buffer.GetNativeBuffer() + byte_offset));
                                             ^
../src/aliased_buffer.h: In member function ‘node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference& node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::operator=(const NativeT&)’:
../src/aliased_buffer.h:121:24: error: request for member ‘SetValue’ in ‘((node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       aliased_buffer_->SetValue(index_, val);
                        ^
../src/aliased_buffer.h: In member function ‘node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::operator NativeT() const’:
../src/aliased_buffer.h:130:31: error: request for member ‘GetValue’ in ‘((const node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       return aliased_buffer_->GetValue(index_);
                               ^
../src/aliased_buffer.h: In member function ‘node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference& node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::operator+=(const NativeT&)’:
../src/aliased_buffer.h:134:48: error: request for member ‘GetValue’ in ‘((node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       const NativeT current = aliased_buffer_->GetValue(index_);
                                                ^
../src/aliased_buffer.h:135:24: error: request for member ‘SetValue’ in ‘((node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       aliased_buffer_->SetValue(index_, current + val);
                        ^
../src/aliased_buffer.h: In member function ‘node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference& node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::operator-=(const NativeT&)’:
../src/aliased_buffer.h:144:48: error: request for member ‘GetValue’ in ‘((node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       const NativeT current = aliased_buffer_->GetValue(index_);
                                                ^
../src/aliased_buffer.h:145:24: error: request for member ‘SetValue’ in ‘((node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference*)this)->node::AliasedBufferBase<NativeT, V8T, <template-parameter-1-3> >::Reference::aliased_buffer_->’, which is of non-class type ‘int’
       aliased_buffer_->SetValue(index_, current - val);
                        ^
../src/aliased_buffer.h: At global scope:
../src/aliased_buffer.h:254:50: error: template argument 3 is invalid
 typedef AliasedBufferBase<int32_t, v8::Int32Array> AliasedInt32Array;
                                                  ^
...
make[1]: Leaving directory `/root/node-v12.16.3/out'
make: *** [node] Error 2

答案1

今天我花了很长时间看这个,看起来解决方案 90% 都封装在节点源文档。如何安装 v.14.x(因为 15 有点太新,而 14 则经过了更好的现场测试)...

Node.js v14.x

作为根用户

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

没有root权限

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

不过,安装版本后curl,您必须刷新元数据缓存,以触发yum update使用最新的可用依赖项进行构建。否则,yum update将继续首选旧的依赖项,它与新的包不兼容。清除元数据缓存yum clean all,所以,一起...

yum remove node npm nodesource-release-el7-1
curl -fsSL https://rpm.nodesource.com/setup_14.x | sudo bash -
yum clean all
yum update

答案2

您似乎已经npm安装了旧版本,需要nodejs = 1:6.17.1-1.el7.也尝试升级 npm。奇怪的是,yum不建议你这样做。尝试这样做来强制他也升级 npm:

yum install nodejs npm

相关内容