项目场景:
项目场景:Ubunto fabrci-samples/test-network v2.1.0,在打包chaincode的过程中报错不能打包失败。
问题描述:
执行
./network.sh deployCC
会遇到权限不足的问题。
所以执行
sudo ./network.sh deployCC
chaincode 打包失败:
eploying chaincode on channel 'mychannel'
Vendoring Go dependencies ...
/home/lizhe/go/src/fabric-samples/chaincode/fabcar/go /home/lizhe/go/src/fabric-samples/test-network
scripts/deployCC.sh: line 24: go: command not found
/home/lizhe/go/src/fabric-samples/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=1
++ set +x
Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
原因分析:
提示scripts/deployCC.sh:line 24: go : command not found,但是确定环境中go已经安装,并且报错的命令为go mod,且确定可以使用。最终发现是应为sudo的原因会重置环境变量导致查找不到可执行的go程序,也就是报错如下
Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
!!!!!!!!!!!!!!! Chaincode packaging on peer0.org1 has failed !!!!!!!!!!!!!!!!
解决方案:
根据网上解决sudo环境变量的问题
在自己的shell配置文件中如下设置
vim ~/.bashrc 或者 vim ~/.bash_profile 等 添加如下
alias sudo='sudo env PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH'
source .bashrc
source .bash_profile
返回test-network目录
sudo ./network.sh deployCC
Vendoring Go dependencies ...
/home/lizhe/go/src/fabric-samples/chaincode/fabcar/go /home/lizhe/go/src/fabric-samples/test-network
/home/lizhe/go/src/fabric-samples/test-network
Finished vendoring Go dependencies
Using organization 1
++ peer lifecycle chaincode package fabcar.tar.gz --path /home/lizhe/go/src/fabric-samples/chaincode/fabcar/go/ --lang golang --label fabcar_1
++ res=0
++ set +x
===================== Chaincode is packaged on peer0.org1 =====================
打包成功!