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.
<code>$ go get -u golang.org/x/sys</code>The command fails, as shown in the screenshot.
Set Proxy
If you have a proxy server, set the environment variables
http_proxyand
https_proxyto point to it.
<code>export http_proxy=http://proxyAddress:port
export https_proxy=http://proxyAddress:port</code>Example with proxy
192.168.21.1:1080:
<code>export http_proxy=http://192.168.21.1:1080
export https_proxy=http://192.168.21.1:1080</code>After setting the proxy, the
go getcommand succeeds.
<code>$ go get -u golang.org/x/sys</code>Manual 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.
<code>mkdir $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone [email protected]:golang/text.git</code>Note: 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=onand add a
replacedirective in
go.modto map the blocked package to a reachable repository.
<code>module example.com/demo
require (
golang.org/x/text v0.3.0
)
replace (
golang.org/x/text => github.com/golang/text v0.3.0
)</code>Use GOPROXY
Go 1.11 also introduces the
GOPROXYenvironment variable. Setting it to a proxy such as
https://goproxy.ioallows downloading blocked packages without additional configuration.
<code>export GO111MODULE=on
export GOPROXY=https://goproxy.io</code>On Windows PowerShell:
<code>$env:GOPROXY = "https://goproxy.io"</code>After setting, the command succeeds and the package is stored under
$GOPATH/pkg/mod/golang.org/x/.
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.