How to Resolve golang.org/x Package Download Failures with Proxies and Go Modules
This guide explains why Go commands often cannot download golang.org/x packages, and provides step‑by‑step solutions including setting HTTP/HTTPS proxies, manually cloning mirror repositories, using go.mod replace directives, and configuring the GOPROXY environment variable to ensure reliable dependency retrieval.
Problem Description
When using go get, go install, or go mod, packages under golang.org/x/... frequently fail to download, interrupting development work. $ go get -u golang.org/x/sys The command fails, as shown in the screenshot.
Set Proxy
If you have a proxy server, set the environment variables http_proxy and https_proxy to point to it.
export http_proxy=http://proxyAddress:port
export https_proxy=http://proxyAddress:portExample with proxy 192.168.21.1:1080:
export http_proxy=http://192.168.21.1:1080
export https_proxy=http://192.168.21.1:1080After setting the proxy, the go get command succeeds.
$ go get -u golang.org/x/sysManual Download
If no proxy is available, you can manually clone a mirror repository from GitHub (e.g., zieckey/golang.org) into $GOPATH/src/golang.org/x.
mkdir $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone [email protected]:golang/text.gitNote: this method cannot specify versions because most mirrors lack tags.
Use go mod replace
Since Go 1.11, modules are supported. Enable modules with export GO111MODULE=on and add a replace directive in go.mod to map the blocked package to a reachable repository.
module example.com/demo
require (
golang.org/x/text v0.3.0
)
replace (
golang.org/x/text => github.com/golang/text v0.3.0
)Use GOPROXY
Go 1.11 also introduces the GOPROXY environment variable. Setting it to a proxy such as https://goproxy.io allows downloading blocked packages without additional configuration.
export GO111MODULE=on
export GOPROXY=https://goproxy.ioOn Windows PowerShell: $env:GOPROXY = "https://goproxy.io" After setting, the command succeeds and the package is stored under $GOPATH/pkg/mod/golang.org/x/.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
