2

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.

4
  • Can you try go to the error: scripts/deployCC.sh: line 59: go: command not found scripts/deployCC.sh line 59 and before the command to run Go, insert your debugging info eg. which go whereis go env etc and see why it is not finding it and what has changed at this point? Commented May 6, 2023 at 1:21
  • Your version of Go is helplessly outdated. Commented May 6, 2023 at 6:16
  • @Volker I used go1.20.4 also. It produces the same error. Not about version I think. Commented May 6, 2023 at 10:19
  • @jamylak I added which go and whereis go before the related line. The result is strangely returns empty. The result is just one line > go: Commented May 6, 2023 at 10:49

3 Answers 3

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

This was the problem. This solved my problem, big thanks!
0

Based on your go env and whereis go outputs, it seems that Go is installed in /home/umitkilic/go/ and the go binary is located in /home/umitkilic/go/bin/go. "go: command not found" error is evidence that go binary is not in your system's PATH. Add it to path as:

# In your .bashrc file
export PATH=$PATH:/home/umitkilic/go/bin

Now, reload your ~/.bashrc file with source ~/.bashrc. After this, you should be able to check the version of Go by go version.

Then, retry your deployment again.

1 Comment

I already have "export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin" in my bashrc file as stated in question. Nevertheless, your suggestion is added to .bashrc. The results is the same. whereis go still produce /home/umitkilic/go/bin/go and error stays.
0

Install with sudo apt-get install golang then deploy the chain code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.