如何解决Node.js npm ERR! Failed at xxx install script 'node-gyp rebuild'?
CentOS
今天在vps上安装一个npm nodejieba时报了一大堆错误:
0 info it worked if it ends with ok
1 verbose cli [ '/root/.nvm/versions/node/v4.1.1/bin/node',
1 verbose cli '/root/.nvm/versions/node/v4.1.1/bin/npm',
1 verbose cli 'install',
1 verbose cli 'nodejieba' ]
2 info using npm@2.14.4
3 info using node@v4.1.1
4 verbose install initial load of /www/web/amz/package.json
5 warn package.json project-name@0.1.0 No README data
6 warn package.json project-name@0.1.0 No license field.
7 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/async/package.json
8 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/cheerio/package.json
9 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/cloudinary/package.json
10 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/cron/package.json
11 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/feed-read/package.json
12 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/iconv-lite/package.json
13 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/moment/package.json
14 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/nan/package.json
15 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/read-art/package.json
16 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/request/package.json
17 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/stable/package.json
18 verbose installManyTop reading scoped package data from /www/web/amz/node_modules/wordpress/package.json
19 info package.json cron@1.0.9 No license field.
20 info package.json cloudinary@1.2.4 No license field.
21 info package.json feed-read@0.0.1 No license field.
22 verbose readDependencies loading dependencies from /www/web/amz/package.json
23 silly cache add args [ 'nodejieba@latest', null ]
24 verbose cache add spec nodejieba@latest
25 silly cache add parsed spec Result {
25 silly cache add raw: 'nodejieba@latest',
25 silly cache add scope: null,
25 silly cache add name: 'nodejieba',
25 silly cache add rawSpec: 'latest',
25 silly cache add spec: 'latest',
25 silly cache add type: 'tag' }
26 silly addNamed nodejieba@latest
27 verbose addNamed "latest" is being treated as a dist-tag for nodejieba
28 info addNameTag [ 'nodejieba', 'latest' ]
29 silly mapToRegistry name nodejieba
30 silly mapToRegistry using default registry
31 silly mapToRegistry registry https://registry.npmjs.org/
32 silly mapToRegistry uri https://registry.npmjs.org/nodejieba
33 verbose addNameTag registry:https://registry.npmjs.org/nodejieba not in flight; fetching
34 verbose request uri https://registry.npmjs.org/nodejieba
35 verbose request no auth needed
36 info attempt registry request try #1 at 12:21:36
37 verbose request id b4db490f11ed05b4
38 verbose etag "DM0FOBI60VJC7UW30FWVP4Q4L"
39 http request GET https://registry.npmjs.org/nodejieba
40 http 304 https://registry.npmjs.org/nodejieba
41 silly get cb [ 304,
41 silly get { date: 'Sat, 09 Apr 2016 04:21:36 GMT',
41 silly get via: '1.1 varnish',
41 silly get 'cache-control': 'max-age=300',
41 silly get etag: '"DM0FOBI60VJC7UW30FWVP4Q4L"',
41 silly get age: '0',
41 silly get connection: 'keep-alive',
41 silly get 'x-served-by': 'cache-dfw1825-DFW',
41 silly get 'x-cache': 'MISS',
41 silly get 'x-cache-hits': '0',
41 silly get 'x-timer': 'S1460175696.438356,VS0,VE257',
41 silly get vary: 'Accept-Encoding' } ]
42 verbose etag https://registry.npmjs.org/nodejieba from cache
43 verbose get saving nodejieba to /root/.npm/registry.npmjs.org/nodejieba/.cache.json
44 silly addNameTag next cb for nodejieba with tag latest
45 silly addNamed nodejieba@1.4.10
46 verbose addNamed "1.4.10" is a plain semver version for nodejieba
47 silly cache afterAdd nodejieba@1.4.10
48 verbose afterAdd /root/.npm/nodejieba/1.4.10/package/package.json not in flight; writing
49 verbose afterAdd /root/.npm/nodejieba/1.4.10/package/package.json written
50 silly install resolved [ { name: 'nodejieba',
50 silly install resolved description: 'chinese word segmentation for node',
50 silly install resolved version: '1.4.10',
50 silly install resolved author: { name: 'Yanyi Wu', email: 'i@yanyiwu.com' },
50 silly install resolved maintainers: [ [Object] ],
50 silly install resolved main: './index.js',
50 silly install resolved engines: { node: '>= 0.10.0', iojs: '>= 1.0.0' },
50 silly install resolved repository:
50 silly install resolved { type: 'git',
50 silly install resolved url: 'git+ssh://git@github.com/yanyiwu/nodejieba.git' },
50 silly install resolved keywords: [ 'chinese', 'segment', 'cppjieba', 'jieba', '中文分词', '结巴分词' ],
50 silly install resolved dependencies: { nan: '~2.2.0' },
50 silly install resolved devDependencies:
50 silly install resolved { mocha: '~2.3.4',
50 silly install resolved should: '~8.0.2',
50 silly install resolved istanbul: '~0.4.1',
50 silly install resolved coveralls: '~2.11.6' },
50 silly install resolved scripts:
50 silly install resolved { test: 'node test/demo.js && node test/load_dict_demo.js && mocha --timeout 10s -R spec test/test.js && mocha --timeout 10s -R spec test/load_dict_test.js',
50 silly install resolved install: 'node-gyp rebuild' },
50 silly install resolved license: 'MIT',
50 silly install resolved gypfile: true,
50 silly install resolved gitHead: '59e958f8da83f133d3d055103cdcc252e4b98799',
50 silly install resolved bugs: { url: 'https://github.com/yanyiwu/nodejieba/issues' },
50 silly install resolved homepage: 'https://github.com/yanyiwu/nodejieba#readme',
50 silly install resolved _id: 'nodejieba@1.4.10',
50 silly install resolved _shasum: '6696b9ea8a439a1c326a083852ee1a20b6035c1a',
50 silly install resolved _from: 'nodejieba@latest',
50 silly install resolved _npmVersion: '3.6.0',
50 silly install resolved _nodeVersion: '5.7.0',
50 silly install resolved _npmUser: { name: 'yanyiwu', email: 'i@yanyiwu.com' },
50 silly install resolved dist:
50 silly install resolved { shasum: '6696b9ea8a439a1c326a083852ee1a20b6035c1a',
50 silly install resolved tarball: 'https://registry.npmjs.org/nodejieba/-/nodejieba-1.4.10.tgz' },
50 silly install resolved _npmOperationalInternal:
50 silly install resolved { host: 'packages-12-west.internal.npmjs.com',
50 silly install resolved tmp: 'tmp/nodejieba-1.4.10.tgz_1458384275507_0.7868719699326903' },
50 silly install resolved directories: {},
50 silly install resolved _resolved: 'https://registry.npmjs.org/nodejieba/-/nodejieba-1.4.10.tgz',
50 silly install resolved readme: 'ERROR: No README data found!' } ]
51 info install nodejieba@1.4.10 into /www/web/amz
52 info installOne nodejieba@1.4.10
53 verbose installOne of nodejieba to /www/web/amz not in flight; installing
54 verbose lock using /root/.npm/_locks/nodejieba-d3939d18b7da3818.lock for /www/web/amz/node_modules/nodejieba
55 silly install write writing nodejieba 1.4.10 to /www/web/amz/node_modules/nodejieba
56 verbose unbuild node_modules/nodejieba
57 silly gentlyRm /www/web/amz/node_modules/nodejieba is being purged from base /www/web/amz
58 verbose gentlyRm don't care about contents; nuking /www/web/amz/node_modules/nodejieba
59 verbose tar unpack /root/.npm/nodejieba/1.4.10/package.tgz
60 verbose tar unpacking to /www/web/amz/node_modules/nodejieba
61 silly gentlyRm /www/web/amz/node_modules/nodejieba is being purged
62 verbose gentlyRm don't care about contents; nuking /www/web/amz/node_modules/nodejieba
63 silly gunzTarPerm modes [ '755', '644' ]
64 silly gunzTarPerm extractEntry package.json
65 silly gunzTarPerm modified mode [ 'package.json', 436, 420 ]
66 silly gunzTarPerm extractEntry .npmignore
67 silly gunzTarPerm modified mode [ '.npmignore', 436, 420 ]
68 silly gunzTarPerm extractEntry README.md
69 silly gunzTarPerm modified mode [ 'README.md', 436, 420 ]
70 silly gunzTarPerm extractEntry index.js
71 silly gunzTarPerm modified mode [ 'index.js', 436, 420 ]
72 silly gunzTarPerm extractEntry README_EN.md
73 silly gunzTarPerm modified mode [ 'README_EN.md', 436, 420 ]
74 silly gunzTarPerm extractEntry binding.gyp
75 silly gunzTarPerm modified mode [ 'binding.gyp', 436, 420 ]
76 silly gunzTarPerm extractEntry .travis.yml
77 silly gunzTarPerm modified mode [ '.travis.yml', 436, 420 ]
78 silly gunzTarPerm extractEntry deps/cppjieba/MPSegment.hpp
79 silly gunzTarPerm extractEntry deps/cppjieba/DictTrie.hpp
80 silly gunzTarPerm modified mode [ 'deps/cppjieba/DictTrie.hpp', 436, 420 ]
81 silly gunzTarPerm extractEntry deps/cppjieba/HMMModel.hpp
82 silly gunzTarPerm modified mode [ 'deps/cppjieba/HMMModel.hpp', 436, 420 ]
83 silly gunzTarPerm extractEntry deps/cppjieba/HMMSegment.hpp
84 silly gunzTarPerm extractEntry deps/cppjieba/Jieba.hpp
85 silly gunzTarPerm extractEntry deps/cppjieba/KeywordExtractor.hpp
86 silly gunzTarPerm modified mode [ 'deps/cppjieba/KeywordExtractor.hpp', 436, 420 ]
87 silly gunzTarPerm extractEntry deps/cppjieba/LevelSegment.hpp
88 silly gunzTarPerm extractEntry deps/cppjieba/FullSegment.hpp
89 silly gunzTarPerm extractEntry deps/cppjieba/MixSegment.hpp
90 silly gunzTarPerm extractEntry deps/cppjieba/PosTagger.hpp
91 silly gunzTarPerm modified mode [ 'deps/cppjieba/PosTagger.hpp', 436, 420 ]
92 silly gunzTarPerm extractEntry deps/cppjieba/PreFilter.hpp
93 silly gunzTarPerm extractEntry deps/cppjieba/QuerySegment.hpp
94 silly gunzTarPerm extractEntry deps/cppjieba/SegmentBase.hpp
95 silly gunzTarPerm extractEntry deps/cppjieba/TransCode.hpp
96 silly gunzTarPerm modified mode [ 'deps/cppjieba/TransCode.hpp', 436, 420 ]
97 silly gunzTarPerm extractEntry deps/cppjieba/Trie.hpp
98 silly gunzTarPerm modified mode [ 'deps/cppjieba/Trie.hpp', 436, 420 ]
99 silly gunzTarPerm extractEntry deps/limonp/ForcePublic.hpp
100 silly gunzTarPerm modified mode [ 'deps/limonp/ForcePublic.hpp', 436, 420 ]
101 silly gunzTarPerm extractEntry deps/limonp/ArgvContext.hpp
102 silly gunzTarPerm modified mode [ 'deps/limonp/ArgvContext.hpp', 436, 420 ]
103 silly gunzTarPerm extractEntry deps/limonp/BoundedBlockingQueue.hpp
104 silly gunzTarPerm modified mode [ 'deps/limonp/BoundedBlockingQueue.hpp', 436, 420 ]
105 silly gunzTarPerm extractEntry deps/limonp/BoundedQueue.hpp
106 silly gunzTarPerm modified mode [ 'deps/limonp/BoundedQueue.hpp', 436, 420 ]
107 silly gunzTarPerm extractEntry deps/limonp/Closure.hpp
108 silly gunzTarPerm modified mode [ 'deps/limonp/Closure.hpp', 436, 420 ]
109 silly gunzTarPerm extractEntry deps/limonp/Colors.hpp
110 silly gunzTarPerm modified mode [ 'deps/limonp/Colors.hpp', 436, 420 ]
111 silly gunzTarPerm extractEntry deps/limonp/Condition.hpp
112 silly gunzTarPerm modified mode [ 'deps/limonp/Condition.hpp', 436, 420 ]
113 silly gunzTarPerm extractEntry deps/limonp/Config.hpp
114 silly gunzTarPerm modified mode [ 'deps/limonp/Config.hpp', 436, 420 ]
115 silly gunzTarPerm extractEntry deps/limonp/FileLock.hpp
116 silly gunzTarPerm modified mode [ 'deps/limonp/FileLock.hpp', 436, 420 ]
117 silly gunzTarPerm extractEntry deps/limonp/BlockingQueue.hpp
118 silly gunzTarPerm modified mode [ 'deps/limonp/BlockingQueue.hpp', 436, 420 ]
119 silly gunzTarPerm extractEntry deps/limonp/LocalVector.hpp
120 silly gunzTarPerm modified mode [ 'deps/limonp/LocalVector.hpp', 436, 420 ]
121 silly gunzTarPerm extractEntry deps/limonp/Logging.hpp
122 silly gunzTarPerm modified mode [ 'deps/limonp/Logging.hpp', 436, 420 ]
123 silly gunzTarPerm extractEntry deps/limonp/Md5.hpp
124 silly gunzTarPerm modified mode [ 'deps/limonp/Md5.hpp', 436, 420 ]
125 silly gunzTarPerm extractEntry deps/limonp/MutexLock.hpp
126 silly gunzTarPerm modified mode [ 'deps/limonp/MutexLock.hpp', 436, 420 ]
127 silly gunzTarPerm extractEntry deps/limonp/NonCopyable.hpp
128 silly gunzTarPerm modified mode [ 'deps/limonp/NonCopyable.hpp', 436, 420 ]
129 silly gunzTarPerm extractEntry deps/limonp/StdExtension.hpp
130 silly gunzTarPerm modified mode [ 'deps/limonp/StdExtension.hpp', 436, 420 ]
131 silly gunzTarPerm extractEntry deps/limonp/StringUtil.hpp
132 silly gunzTarPerm modified mode [ 'deps/limonp/StringUtil.hpp', 436, 420 ]
133 silly gunzTarPerm extractEntry deps/limonp/Thread.hpp
134 silly gunzTarPerm modified mode [ 'deps/limonp/Thread.hpp', 436, 420 ]
135 silly gunzTarPerm extractEntry deps/limonp/ThreadPool.hpp
136 silly gunzTarPerm modified mode [ 'deps/limonp/ThreadPool.hpp', 436, 420 ]
137 silly gunzTarPerm extractEntry dict/hmm_model.utf8
138 silly gunzTarPerm modified mode [ 'dict/hmm_model.utf8', 436, 420 ]
139 silly gunzTarPerm extractEntry dict/idf.utf8
140 silly gunzTarPerm modified mode [ 'dict/idf.utf8', 436, 420 ]
141 silly gunzTarPerm extractEntry dict/jieba.dict.utf8
142 silly gunzTarPerm modified mode [ 'dict/jieba.dict.utf8', 436, 420 ]
143 silly gunzTarPerm extractEntry dict/stop_words.utf8
144 silly gunzTarPerm modified mode [ 'dict/stop_words.utf8', 436, 420 ]
145 silly gunzTarPerm extractEntry dict/user.dict.utf8
146 silly gunzTarPerm modified mode [ 'dict/user.dict.utf8', 436, 420 ]
147 silly gunzTarPerm extractEntry ChangeLog.md
148 silly gunzTarPerm modified mode [ 'ChangeLog.md', 436, 420 ]
149 silly gunzTarPerm extractEntry lib/index.cpp
150 silly gunzTarPerm modified mode [ 'lib/index.cpp', 436, 420 ]
151 silly gunzTarPerm extractEntry lib/nodejieba.cpp
152 silly gunzTarPerm modified mode [ 'lib/nodejieba.cpp', 436, 420 ]
153 silly gunzTarPerm extractEntry lib/nodejieba.h
154 silly gunzTarPerm modified mode [ 'lib/nodejieba.h', 436, 420 ]
155 silly gunzTarPerm extractEntry lib/utils.h
156 silly gunzTarPerm modified mode [ 'lib/utils.h', 436, 420 ]
157 silly gunzTarPerm extractEntry test/demo.js
158 silly gunzTarPerm modified mode [ 'test/demo.js', 436, 420 ]
159 silly gunzTarPerm extractEntry test/load_dict_demo.js
160 silly gunzTarPerm modified mode [ 'test/load_dict_demo.js', 436, 420 ]
161 silly gunzTarPerm extractEntry test/load_dict_test.js
162 silly gunzTarPerm modified mode [ 'test/load_dict_test.js', 436, 420 ]
163 silly gunzTarPerm extractEntry test/test.js
164 silly gunzTarPerm modified mode [ 'test/test.js', 436, 420 ]
165 silly gunzTarPerm extractEntry test/testdata/userdict.utf8
166 silly gunzTarPerm modified mode [ 'test/testdata/userdict.utf8', 436, 420 ]
167 verbose write writing to /www/web/amz/node_modules/nodejieba/package.json
168 info preinstall nodejieba@1.4.10
169 verbose readDependencies loading dependencies from /www/web/amz/node_modules/nodejieba/package.json
170 verbose readDependencies loading dependencies from /www/web/amz/node_modules/nodejieba/package.json
171 silly install resolved []
172 verbose about to build /www/web/amz/node_modules/nodejieba
173 info build /www/web/amz/node_modules/nodejieba
174 info linkStuff nodejieba@1.4.10
175 silly linkStuff nodejieba@1.4.10 has /www/web/amz/node_modules as its parent node_modules
176 verbose linkBins nodejieba@1.4.10
177 verbose linkMans nodejieba@1.4.10
178 verbose rebuildBundles nodejieba@1.4.10
179 info install nodejieba@1.4.10
180 verbose unsafe-perm in lifecycle false
181 info nodejieba@1.4.10 Failed to exec install script
182 verbose unlock done using /root/.npm/_locks/nodejieba-d3939d18b7da3818.lock for /www/web/amz/node_modules/nodejieba
183 verbose stack Error: nodejieba@1.4.10 install: `node-gyp rebuild`
183 verbose stack Exit status 1
183 verbose stack at EventEmitter.<anonymous> (/root/.nvm/versions/node/v4.1.1/lib/node_modules/npm/lib/utils/lifecycle.js:214:16)
183 verbose stack at emitTwo (events.js:87:13)
183 verbose stack at EventEmitter.emit (events.js:172:7)
183 verbose stack at ChildProcess.<anonymous> (/root/.nvm/versions/node/v4.1.1/lib/node_modules/npm/lib/utils/spawn.js:24:14)
183 verbose stack at emitTwo (events.js:87:13)
183 verbose stack at ChildProcess.emit (events.js:172:7)
183 verbose stack at maybeClose (internal/child_process.js:817:16)
183 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
184 verbose pkgid nodejieba@1.4.10
185 verbose cwd /www/web/amz
186 error Linux 2.6.32-042stab108.5
187 error argv "/root/.nvm/versions/node/v4.1.1/bin/node" "/root/.nvm/versions/node/v4.1.1/bin/npm" "install" "nodejieba"
188 error node v4.1.1
189 error npm v2.14.4
190 error code ELIFECYCLE
191 error nodejieba@1.4.10 install: `node-gyp rebuild`
191 error Exit status 1
192 error Failed at the nodejieba@1.4.10 install script 'node-gyp rebuild'.
192 error This is most likely a problem with the nodejieba package,
192 error not with npm itself.
192 error Tell the author that this fails on your system:
192 error node-gyp rebuild
192 error You can get their info via:
192 error npm owner ls nodejieba
192 error There is likely additional logging output above.
193 verbose exit [ 1, true ]
194 verbose unbuild node_modules/nodejieba
195 info preuninstall nodejieba@1.4.10
196 info uninstall nodejieba@1.4.10
197 verbose unbuild rmStuff nodejieba@1.4.10 from /www/web/amz/node_modules
198 info postuninstall nodejieba@1.4.10
199 silly gentlyRm /www/web/amz/node_modules/nodejieba is being purged from base /www/web/amz
200 verbose gentlyRm don't care about contents; nuking /www/web/amz/node_modules/nodejieba
201 silly vacuum-fs purging /www/web/amz/node_modules/nodejieba
202 silly vacuum-fs quitting because other entries in /www/web/amz/node_modules
可是在本地安装nodejieba时是没有错误的。那么可能的原因一是npm包本身有兼容性问题,二是这个所谓的node-gyp build需要的gcc 或者 g++有兼容性问题。
只能一个个排除了:
- 首先看了nodejieba的github是没有问题的;
- 然后上网找了个CentOS升级gcc和g++的方法:
cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo
yum --enablerepo=testing-1.1-devtools-6 install devtoolset-1.1-gcc devtoolset-1.1-gcc-c++
/opt/centos/devtoolset-1.1/root/usr/bin/
ln -s /opt/centos/devtoolset-1.1/root/usr/bin/* /usr/local/bin/
hash -r
查看g++的版本号:
g++ --version
看到如下信息就说明OK了:
g++ (GCC) 4.7.2 20121015 (Red Hat 4.7.2-5)
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
然后,再重新npm install nodejieba就没有错误了。
如果你的系统是Ubuntu
那么可能需要将gcc和g++升级到4.8,才能支持安装nodejieba。安装方法请看Linux(ubuntu)+gcc/g++ 升级。