2

I tried npm node-gyp -g but it didn't help. I am trying to install truffle in my mac. I am using mac os Catalina, node version 16.13.1, and npm version 8.1.2

npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/builder.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.1 | darwin | x64
npm ERR! gyp info find Python using Python version 3.8.1 found at "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-/c++/v1/string:505:
...
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown
npm ERR! gyp ERR! node -v v16.13.1
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok
TylerH
  • 20,799
  • 66
  • 75
  • 101

2 Answers2

1

Refer to https://github.com/trufflesuite/truffle/issues/4692 , So for workaround we have to...

For non-nvm

# Install npm 6
npm i -g npm@6

# Make sure should get npm `6.14.15`
npm --version

# Should work now
npm i -g truffle

For nvm

# In case you have 16 installed (you can skip this)
npm config delete prefix

# Get npm 6.14.16 from node 14 (or you can try install only npm)
nvm use 14

# Make sure should get npm `6.14.15`
npm --version

# Should work now
npm i -g truffle
Dharman
  • 30,962
  • 25
  • 85
  • 135
katopz
  • 591
  • 6
  • 14
1

Above answer did not work for me

Try this :

sudo npm install -g truffle --unsafe-perm

Source : https://github.com/nodejs/node-gyp/issues/2631
Mehdi LAMRANI
  • 11,289
  • 14
  • 88
  • 130