How to Fix Golang.org/x Package Download Failures with Proxies and Go Modules
This guide explains why Go commands like go get fail to download golang.org/x packages, and provides step‑by‑step solutions using HTTP/HTTPS proxy settings, manual repository cloning, go.mod replace directives, and the GOPROXY environment variable to reliably fetch dependencies.
When developing Go projects, downloading certain dependencies such as packages under golang.org/x/ often fails, interrupting work. This article presents several permanent solutions.
Problem Description
Commands like go get, go install, and go mod cannot download packages from golang.org/x/.... For example: go get -u golang.org/x/sys The download fails, as shown in the screenshot below.
Set Proxy
If you have a proxy server, set the http_proxy and https_proxy environment variables:
export http_proxy=http://proxyAddress:port
export https_proxy=http://proxyAddress:portExample using a local 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 command succeeds:
go get -u golang.org/x/sysManual Download and Install
If a proxy is unavailable, you can manually clone the 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 https://github.com/zieckey/golang.org.git # or clone a specific sub‑repo
# Example: clone the text package
git clone https://github.com/golang/text.gitNote that most mirror repositories lack tags, so specifying exact versions may be impossible.
Use go.mod Replace
Since Go 1.11, modules support a replace directive to alias packages, which can also solve the download issue.
Enable modules (if your code resides in $GOPATH): export GO111MODULE=on Example go.mod:
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 Environment Variable
Go 1.11 also introduced the GOPROXY variable. Setting it directs the Go toolchain to download modules through a proxy such as https://goproxy.io instead of accessing the original source directly.
export GO111MODULE=on
export GOPROXY=https://goproxy.ioTo disable the proxy, set GOPROXY=.
Windows PowerShell example: $env:GOPROXY = "https://goproxy.io" We recommend using the GOPROXY method for Go versions ≥ 1.11.
Final Download
Now the package can be fetched successfully:
go get -u golang.org/x/sysThe downloaded package resides in $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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
