配置GOPATH后仍无法下载fabric-sdk-go,环境配置求助
Hey there! I notice a couple of key issues in your Go environment setup that are likely causing headaches, especially since you're just getting started with Hyperledger Fabric. Let's break this down step by step to get you back on track.
1. Critical Issue: Incorrect GOPATH Setting
Looking at your go env output, your GOPATH is set to /usr/lib/go-1.6/bin—this is a big mistake!
GOPATH is meant to be your Go workspace directory, where you store project source code, compiled packages, and executable binaries. It should never point to the bin folder inside your Go installation directory.
How to Fix GOPATH:
- First, create a proper workspace in your home directory:
mkdir -p $HOME/go/{src,pkg,bin} - Set the GOPATH temporarily (for your current terminal session):
export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin - To make this permanent (so it persists after rebooting), edit your
~/.bashrcfile (or~/.profileif you use that) and add the two lines above. Then apply the changes immediately:source ~/.bashrc - Verify the fix by running
go envagain—yourGOPATHshould now show something like/home/user1/go.
2. Outdated Go Version
Go 1.6 is extremely old (released back in 2016!), and Hyperledger Fabric requires a much newer Go version (most recent Fabric releases need Go 1.18 or later). Using such an outdated version will definitely cause compatibility issues with Fabric's codebase.
How to Upgrade Go:
- Download a stable, supported Go version (e.g., Go 1.20, which is widely used for Fabric):
wget https://dl.google.com/go/go1.20.linux-amd64.tar.gz - Remove the old Go installation:
sudo rm -rf /usr/lib/go-1.6 - Extract the new Go package to the standard installation directory:
sudo tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz - Update your
PATHto use the new Go binary (add this to~/.bashrctoo):export PATH=$PATH:/usr/local/go/bin - Confirm the upgrade worked:
You should see output likego versiongo version go1.20 linux/amd64.
3. Next Steps for Hyperledger Fabric
Once your Go environment is sorted, you'll need to set up other core dependencies for Fabric:
- Docker and Docker Compose (most Fabric components run in containers)
- Fabric official binaries and sample projects (you can use the official
install-fabric.shscript to pull these easily)
Take it one step at a time, and double-check each configuration before moving on—environment setup can be finicky, but getting Go right is a critical foundational step.
内容的提问来源于stack exchange,提问作者Vishnu KR

