Go version 1.16 beta1 has been released on 18 Dec 2020, major features of Go 1.16 have been finalized with this beta release. Many people are discussing about the support of Apple M1, however, this post will not cover this topic. Instead the focus will be on go get
and go install
changes.
There are lots of changes related to modules in Go 1.16, the details can be found in the release note. Below are some of the key highlights.
GO111MODULE
ison
by default, if wanna keep old behavior, needs to set it toauto
. This means that GOPATH would gradually get away from us.go install
can take a version number as suffix. e.g. go install sigs.k8s.io/kind@v0.9.0. And it is module aware which means it would ignore thego.mod
in current directory or parent directory. This would make binary installation easier without changing dependencies stated in go.mod.- In the future,
go install
will be used for binary tool build and installation whilego get
will be mainly for dependency update. go build
andgo test
will not updatego.mod
andgo.sum.
To update them, can rungo mod tidy
orgo get
.
go get
is being used to install binary tools in $GOPATH/bin
until now, but it has a problem where it will update go.mod
as well apart from installing the binary tool and make it as a dependency to the project which may not be needed. To prevent updating the go.mod, normally, one needs to run below:
cd $(mktemp -d); GO111MODULE=on go get sigs.k8s.io/kind@v0.9.0
Since Go 1.16, the above command can be simplified as:
go install sigs.k8s.io/kind@v0.9.0
This looks pretty straightforward. In addition, it will not update go.mod as GO111MODULE is on by default.
One thing to note about go install
is that it would cause error if run it without version when run it outside a module.
go install -v sigs.k8s.io/kind
go install: version is required when current directory is not in a module
Try 'go install sigs.k8s.io/kind@latest' to install the latest version
If run go install
without version in module directory, only versions specified in go.mod would be installed.
In Go 1.16, the function to install binary tool with go get
has been deprecated and developers should use go install
instead. The function to update go.mod
remains. Starting from Go 1.17, the function to install binary tool will be removed from go get
. And later go get
will serve the sole purpose of go get -d
as of now.
When migrating from Go 1.15 to Go 1.16, go mod tidy needs to be ran when doing go build and go test, otherwise go.mod would not be updated.
Reference: Go 1.16 ä¸å…³äºŽ go get å’Œ go install ä½ éœ€è¦æ³¨æ„的地方