linux下npm 安装zeromq遇到的报错,以及最终解决办法

官方给的教程很简单,如下:

//初始化项目目录
npm init -y
 
//安装依赖
npm install zeromq@4

然后就没有然后了。

结果发现问题真多

首先npm安装的时候出现第一个问题:

npm ERR! ----------------------------------------------------------------------
npm ERR! Libraries have been installed in:
npm ERR!    /root/github/nodejs-course/third-party-package/zeromq-demo/node_modules/zeromq/zmq/lib
npm ERR! 
npm ERR! If you ever happen to want to link against installed libraries
npm ERR! in a given directory, LIBDIR, you must either use libtool, and
npm ERR! specify the full pathname of the library, or use the `-LLIBDIR'
npm ERR! flag during linking and do at least one of the following:
npm ERR!    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
npm ERR!      during execution
npm ERR!    - add LIBDIR to the `LD_RUN_PATH' environment variable
npm ERR!      during linking
npm ERR!    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
npm ERR!    - have your system administrator add LIBDIR to `/etc/ld.so.conf'
npm ERR! 
npm ERR! See any operating system documentation about shared libraries for
npm ERR! more information, such as the ld(1) and ld.so(8) manual pages.
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! g++: 错误:unrecognized command line option ‘-std=gnu++14’
npm ERR! make: *** [Release/obj.target/zmq/binding.o] 错误 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2

一大批报错的,认真看,错误在这里:

npm ERR! g++: 错误:unrecognized command line option ‘-std=gnu++14

这个问题是因为你的系统的gcc版本过低。

因为CentOS目前自带的gcc是4.8.5的,需要升级gcc来解决这个问题。当然也有建议使用低版本的node环境重新安装node包的。

因为我用的是是node v16, 不想降级了。于是只能升级gcc.

centos使用yum升级gcc

yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
scl enable devtoolset-8 bash

最后一个命令是在当前的bash下使用gcc8的环境。

如果你想一直用最新的gcc8,可以这样:

echo "source /opt/rh/devtoolset-8/enable" >> /etc/bashrc
source /etc/bashrc 

然后输入命令看看目前的gcc版本:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值