“hyperledger fabric – ‘go’: 在 $PATH 中找不到可执行文件”

huangapple go评论98阅读模式
英文:

hyperledger fabric - "go": executable file not found in $PATH

问题

我是你的中文翻译助手,以下是你要翻译的内容:

我对Hyperleger Fabric还不熟悉,正在尝试完成使用Fabric测试网络文档中的示例。我在启动通道上的链码阶段遇到了问题。尽管我已经正确调整了路径,但仍然出现下面的错误。我无法从类似的问题中找到解决方案。

命令如下:

sudo ./network.sh deployCC -c channeluk1 -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go

以下是输出:

使用docker和docker-compose
在通道'channeluk1'上部署链码
使用以下参数执行

  • 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
    在../asset-transfer-basic/chaincode-go中获取Go依赖项
    ~/go/src/github.com/umitkilic/fabric-samples/asset-transfer-basic/chaincode-go ~/go/src/github.com/umitkilic/fabric-samples/test-network
    脚本deployCC.sh: 第59行:go:找不到命令
    ~/go/src/github.com/umitkilic/fabric-samples/test-network
    完成Go依赖项的获取
  • 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
    错误:无法读取'basic.tar.gz'处的链码包:打开basic.tar.gz时出错:没有该文件或目录
  • PACKAGE_ID=
    错误:无法规范化链码路径:无法确定模块根目录:exec:“go”:在$PATH中找不到可执行文件
    链码打包失败
    部署链码失败

我知道错误提示说GO路径有问题,但路径没有问题。这里是一些关于go的输出。

命令如下:

go env

输出如下:

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"

命令如下:

whereis go

输出如下:

go: /home/umitkilic/go/bin/go

(在go env输出中,GOPATH="/home/umitkilic/go",但在whereis go输出中,它说go: /home/umitkilic/go/bin/go。我不确定这两者是否一致。)

在我的~/.bashrc文件中,我有以下几行:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

我的fabric samples目录是Home/umitkilic/go/src/github.com/umitkilic/fabric-samples

我的go版本是go1.13.15 linux/amd64。

我尝试将go语言安装在/usr/local/go中,但结果仍然是相同的错误。

你能帮助我吗?

更新:
我之前使用了最新版本,例如来自官方网站的go1.20.4,按照他们的说明进行安装。结果仍然是相同的错误。

顺便说一下,我使用以下命令打印fabric peer版本:

docker exec -it cli bash
root@bb4a6d6eed2f:/opt/gopath/src/github.com/hyperledger/fabric/peer# peer version

输出如下:

peer:
版本:v2.5.0
Commit SHA:bd8e248
Go版本:go1.20.2
OS/Arch:linux/amd64
Chaincode:
基本Docker标签:org.hyperledger.fabric
Docker命名空间:hyperledger

它说Go版本是go1.20.2,但我从未下载和安装过这个版本的Go。也许这是与Docker中的fabric samples自动安装的。我不确定它是否与错误相关。

英文:

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.

答案1

得分: 1

问题是您以root用户身份(使用sudo)运行脚本。而root用户有自己的环境变量。您可以通过以下方式验证root用户的$PATH中是否没有go命令:

$ sudo sh
# echo $PATH

root用户和当前登录用户之间可能存在太多环境差异。例如,root用户具有可能会影响go命令的不同$GOENV。因此,我的建议是:不要费心修改root用户的$PATH;相反,以非root用户身份运行Docker守护程序(还可以参考这个问题:https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo)。

然后在没有sudo的情况下执行脚本:

./network.sh deployCC -c channeluk1 -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
英文:

> 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

答案2

得分: 0

根据您的go env和whereis go输出,似乎Go已安装在/home/umitkilic/go/,go二进制文件位于/home/umitkilic/go/bin/go。"go: command not found"错误表明go二进制文件不在系统的PATH中。请将其添加到PATH中:

# 在您的.bashrc文件中
export PATH=$PATH:/home/umitkilic/go/bin

现在,使用source ~/.bashrc重新加载您的~/.bashrc文件。之后,您应该能够通过go version检查Go的版本。

然后,再次尝试部署。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月6日 06:06:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76186165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定