npm install时,提示make: g++: Command not found

npm install的时候,可能会出现提示make:g++ Command not found的错误,如下所示:
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/yanyiwu/nodejieba/releases/download/2.4.1/nodejieba-v2.4.1-node-v72-linux-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, glibc) (falling back to source compile with node-gyp)
make: Entering directory /home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build' CXX(target) Release/obj.target/nodejieba/lib/index.o make: g++: Command not found make: *** [Release/obj.target/nodejieba/lib/index.o] Error 127 make: Leaving directory/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build’
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/nodejs/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:310:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 3.10.0-957.21.3.el7.x86_64
gyp ERR! command “/usr/local/nodejs/bin/node” “/usr/local/nodejs/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “build” “–fallback-to-build” “–module=/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build/Release/nodejieba.node” “–module_name=nodejieba” “–module_path=/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build/Release” “–napi_version=5” “–node_abi_napi=napi” “–napi_build_version=0” “–node_napi_label=node-v72”
gyp ERR! cwd /home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute ‘/usr/local/nodejs/bin/node /usr/local/nodejs/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build/Release/nodejieba.node --module_name=nodejieba --module_path=/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/nodejieba/build/Release --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72’ (1)
node-pre-gyp ERR! stack at ChildProcess. (/home/smart/jenkins/workspace/microservice_vue_demo/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:310:20)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)

解决方法:
先安装g++,切换到root用户,执行

root@linx:~# yum install gcc -c++

等待包安装完成后,执行g++ -v查看成功安装了g++

root@linx:~# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 

再重新执行npm install即可。

猜你喜欢

转载自blog.csdn.net/BUG_88/article/details/106011887