Ubuntu 16.04(Node9.11.1、npm5.6.0)安装Solidity开发用web3遇阻
Hey there, let's work through this web3 install problem you're hitting. The errors you're seeing have two main parts: deprecated package warnings and a failed scrypt build (that's the node-gyp rebuild traceback). Here's how to resolve each part step by step:
Step 1: Fix the scrypt Compilation Failure (The Critical Error)
The scrypt package needs system-level build tools and dependencies to compile properly. On Ubuntu 16.04, first install the required packages:
sudo apt-get update && sudo apt-get install build-essential libssl-dev python2.7
Older Node versions like 9.11.1 rely on Python 2.7 for node-gyp builds, so set npm to use it:
npm config set python python2.7
Next, clean your npm cache to get rid of any corrupted leftover files:
npm cache clean --force
Try reinstalling web3 again:
npm install web3
If you still run into permission issues during the install, add the --unsafe-perm flag to bypass permission restrictions for the build process:
npm install web3 --unsafe-perm
Step 2: Address Deprecated Package Warnings
The warnings about fs-promise and tar.gz being deprecated come from older web3 versions that rely on these outdated packages. To fix this, install a web3 version that's compatible with your Node 9.11.1 setup and uses updated dependencies. A reliable choice is web3@1.2.11, which works well with older Node versions:
npm install web3@1.2.11
This version will cut down those deprecation warnings significantly.
Step 3: (Optional) Upgrade Node.js for Better Compatibility
Node 9.11.1 is pretty old and no longer supported. If you can, upgrading to an LTS version (like Node 14.x, which is compatible with Ubuntu 16.04) will make future package installs smoother. Use Node Version Manager (nvm) to manage versions easily—install nvm via its official method, then run:
nvm install 14 nvm use 14
Then reinstall web3 with the latest compatible version:
npm install web3
Your Original Error Log for Reference:
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise Support
npm WARN deprecated tar.gz@1.0.7: WARNING tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead
scrypt@6.0.3 preinstall /home/eschulton/code/solidity/inbox/node_modules/scrypt
node node-scrypt-preinstall.js
scrypt@6.0.3 install /home/eschulton/code/solidity/inbox/node_modules/scrypt
node-gyp rebuild
Traceback (most recent call last):
File "/h...
内容的提问来源于stack exchange,提问作者eschulton

