truffleのinsall でerror :npm ERR! code 127 

1.結論 truffle initは、あきらめた
・今のところTruffleはnpm <7とのみ互換性がある ・一応nstallは出来たが、truffle initでerrorが出る ・どうしても動かしたかったわけではないので、truffle initは保留
2.truffleをinstallした時のERR

# npm install -g truffle
:
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v17.9.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: line 1: node-gyp-build: command not found

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-19T20_47_14_963Z-debug-0.log
#

3.node-gyp-buildを入れる

# npm install node-gyp-build

added 1 package, and audited 4 packages in 2s

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities
# npm ls |grep node-gyp-build
mqq node-gyp-build@4.4.0
#

5.node-gyp-buildの存在確認

# which node-gyp-build
/usr/bin/which: no node-gyp-build in (/root/.nvm/versions/node/v17.9.0/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/var/lib/snapd/snap/bin)

4.pathを追加

# vi ~/.bashrc

PATH="$HOME/./node_modules/.bin/:$PATH"
export PATH

# source ~/.bashrc

6.またinstallに失敗する
そこで、nvmでnodejsを18に上げる

# nvm install 18
Downloading and installing node v18.2.0...
Downloading https://nodejs.org/dist/v18.2.0/node-v18.2.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.2.0 (npm v8.9.0)
[root@localhost ~]# node -v
v18.2.0
#

7.再度installだが失敗する

# npm install -g truffle
:
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v18.2.0/lib/node_modules/truffle/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: line 1: node-gyp-build: command not found

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-19T21_35_53_530Z-debug-0.log
[root@localhost ~]#

8.githubに以下の書き込みがあるので、npm@6をインストールする

Hey @ukyo717, for now Truffle is only compatible with npm < 7. It looks like you are using version 8, could you try downgrading your npm and installing again? You can do this by entering

# npm install -g npm@6
# node -v
v18.2.0
# npm install -g truffle
:
+ truffle@5.5.14
added 1133 packages from 768 contributors in 510.882s
#

9. truffle init
・ここまでやって、以下のエラーがでた。
・Error: Cannot find module ‘./uws_linux_x64_108.node’

# truffle init
This version of μWS is not compatible with your Node.js build:

Error: Cannot find module './uws_linux_x64_108.node'
Falling back to a NodeJS implementation; performance may be degraded.

^C
#

10.対応
・’./uws_linux_x64_108.” ” node’が検索で引き当たらない

11.手順を見直したら、nodeのversionが <7 になっていない
・どうしても動かしたかったわけではないので、truffle initは一旦保留

12.参考
https://github.com/trufflesuite/truffle/issues/4692