I 'm new to Hyperleger Fabric and trying to done examples from Using the Fabric test network documentation. I'm stuck on the phase of starting a chaincode on the channel. I am getting error located below even though I have adjusted paths properly. I couldn't figure out the solution from similar questions.
The command:
sudo ./network.sh deployCC -c channeluk1 -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
Here is the output:
> Using docker and docker-compose
deploying chaincode on channel 'channeluk1'
executing with the following
> - CHANNEL_NAME: channeluk1
> - CC_NAME: basic
> - CC_SRC_PATH: ../asset-transfer-basic/chaincode-go
> - CC_SRC_LANGUAGE: go
> - CC_VERSION: 1.0
> - CC_SEQUENCE: 1
> - CC_END_POLICY: NA
> - CC_COLL_CONFIG: NA
> - CC_INIT_FCN: NA
> - DELAY: 3
> - MAX_RETRY: 5
> - VERBOSE: false
> Vendoring Go dependencies at ../asset-transfer-basic/chaincode-go
~/go/src/github.com/umitkilic/fabric-samples/asset-transfer-basic/chaincode-go ~/go/src/github.com/umitkilic/fabric-samples/test-network
scripts/deployCC.sh: line 59: go: command not found
~/go/src/github.com/umitkilic/fabric-samples/test-network
> Finished vendoring Go dependencies
> + peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
> + res=1
> ++ peer lifecycle chaincode calculatepackageid basic.tar.gz
Error: failed to read chaincode package at 'basic.tar.gz': open basic.tar.gz: no such file or directory
> + PACKAGE_ID=
> Error: failed to normalize chaincode path: failed to determine module root: exec: "go": executable file not found in $PATH
Chaincode packaging has failed
Deploying chaincode failed
I know the error says there is something wrong about GO path but no problem about path. Here is some outputs for go.
Command:
go env
Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/umitkilic/.cache/go-build"
GOENV="/home/umitkilic/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/umitkilic/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/umitkilic/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/umitkilic/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/umitkilic/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build952499924=/tmp/go-build -gno-record-gcc-switches"
Command:
whereis go
Output:
go: /home/umitkilic/go/bin/go
(In go env output, GOPATH="/home/umitkilic/go" but in whereis go output it says go: /home/umitkilic/go/bin/go. I'm not sure if these are in coherent.)
In my ~/.bashrc file I have following lines:
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
My fabric samples directory is Home/umitkilic/go/src/github.com/umitkilic/fabric-samples
My go version go1.13.15 linux/amd64.
I tried to install go language in /usr/local/go but the result is the same error.
Can you help me please?
Update: I used newest version before such as go1.20.4 from official website following their instruction. The result was the same error.
By the way, I used below command to print fabric peer version:
docker exec -it cli bash
root@bb4a6d6eed2f:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer version
The output is:
peer:
Version: v2.5.0
Commit SHA: bd8e248
Go version: go1.20.2
OS/Arch: linux/amd64
Chaincode:
Base Docker Label: org.hyperledger.fabric
Docker Namespace: hyperledger
It says Go version is go1.20.2 but I have never download and install this version of Go. Maybe this automatically installed with fabric samples in Docker. I am not sure wheather it is relevant to the error.
sudo ./network.sh ...
The issue is that you run the script as the root
user (with sudo
). And the root
user has its own environment variables. You can verify that the go
command is not in the root
's $PATH
like this:
$ sudo sh
# echo $PATH
There could be too many environmental differences between root
and the current login user. For example, the root
user has different $GOENV
that could affect the go
command. So my suggestion is: do not bother to modify the root
's $PATH
; instead, run the Docker daemon as a non-root user (also see this question: https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo).
And then execute the script without sudo
:
./network.sh deployCC -c channeluk1 -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go