How to Fix “can’t load package… zip file is too large” with Go

Paul Xiong
1 min readApr 8, 2021

The problem:

$ swag init
...
go get github.com/paulxiong/cervical@1b2d2657e8dab3ba41226f02bbc79fac089290c6:downloaded zip file too larg

To background:

Many engineers have the same issue, posted on stocker overflow and Reddit… The only solution, I did not try, is to separate the repository into smaller repositories(each <500M).

My solution:

Since this limitation is defined by Golang, I will build a go command, called go_new, without the 500M limitation.

(To save the reader’s time, I will NOT write the debug steps here, directly jump to where the code should be modified and how to build it. )

  • copy $GOROOT to a new place and make the new place to be GOROOT:
$ echo $GOROOT 
/usr/local/go
$ mkdir go-new
$cd go-new
$ cp -r $GOROOT ./
$ cd go/src/cmd/go
$ export GOROOT = ~/go-new/go

Modify the source code, extent 500M to 900M, and build the new go :

$ vim internal/modfetch/codehost/codehost.go
change
MaxZipFile = 500 << 20
to
MaxZipFile = 900 << 20
$ go build -o go .

Now we run swag init, it won't have the “…zip file too large” issue anymore.

How to restore to original Go

Change the GOROOT back to the original one, my case (Ubuntu 16.04) is:

export GOROOT= "/usr/local/go"

Important Update:

Digging into more on the “…zip file too large” issue, it was caused by:1)My virtual machine is running Intel-32bit-ubuntu;2)My go distribution is AMD-64bit-ubuntu. After I change my virtual machine to AMD-64bit-ubuntu, the issue is gone.

--

--

Paul Xiong

Coding, implementing, optimizing ML annotation with self-supervised learning, TLDR: doctor’s labeling is the 1st priority for our Cervical AI project.