準備學習solidity,按照書本要求在linux上搭建環境,先后安裝了nodejs、npm等
node -v
v15.8.0
npm -v
7.16.0
然后使用npm安裝cnpm,執行
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
之后使用cnpm安裝web3,執行
sudo cnpm install web3 -g
提示:
Command ‘cnpm’ not found
輸入cnpm -v也是如此,
于是打算跳過,進行下一步用npm安裝ganache-cli和truffle,執行
sudo npm install -g ganache-cli
安裝后顯示:
changed 6 packages in 1s
2 packages are looking for funding
run `npm fund` for details
執行
sudo npm install -g truffle
安裝完成后提示了一些warning:
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated fsevents@2.1.3: "Please update to latest v2.3 or v2.2"
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated debug@4.1.1: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)
npm WARN deprecated remotedev-serialize@0.1.9: Package moved to @redux-devtools/serialize.
npm WARN deprecated redux-devtools-instrument@1.10.0: Package moved to @redux-devtools/instrument.
npm WARN deprecated redux-devtools-core@0.2.1: Package moved to @redux-devtools/app.
npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated multicodec@0.5.7: stable api reached
npm WARN deprecated node-pre-gyp@0.11.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated ethereumjs-common@1.5.2: New versions are published within new scoped package name format @ethereumjs/common. Please update.
npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
changed 886 packages in 2m
此時無法使用ganache和truffle,同樣提示Command not found,懷疑是否安裝成功
查看npm所有全域安裝的模塊,執行npm list -g:
/usr/local/node/node-v15.8.0-linux-x64/lib
├── cnpm@6.2.0
├── ethereumjs-testrpc@6.0.3
├── ganache-cli@6.12.2
├── npm@7.16.0
├── solc@0.8.4
├── truffle@5.3.9
├── web3@1.3.6
└── yarn@1.22.10
應該都已經安裝成功
最終發現是未設定環境變數所致
解決方法:為當前用戶永久添加環境變數
1、先要找到cnpm、truffle等的具體路徑,可使用whereis命令查找,比如我執行whereis truffle會顯示:
truffle: /usr/local/node/node-v15.8.0-linux-x64/bin/truffle
2、編輯用戶目錄下的隱藏檔案.bashrc(執行ls看不到,需要執行ls -a)
在用戶目錄下執行vim .bashrc進入編輯
在檔案末尾添加export PATH="/usr/local/node/node-v15.8.0-linux-x64/bin/:$PATH"
注意:具體的path路徑大家可能不同
3、保存退出后執行命令source ~/.bashrc
成功解決!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/286664.html
標籤:區塊鏈
