By Daniel Martí, Go contributor, maintainer of encoding/json
,
and tool author.
Users need a simple, easy-to-remember way to install Go programs. Similarly, tool authors need a short one-liner they
can include at the top of their README.md
explaining how to install the tool.
Go 1.16 introduced a new way to install Go programs directly with the go
command. This guide
introduces the new mode of go install
using the example of
filippo.io/mkcert
, and is suitable for both end users and tool authors.
Prerequisites
You should already have completed:
This guide is running with:
$ go version
go version go1.19.1 linux/amd64
go install
in Go 1.16
As of Go 1.16, the go install
command is now used to install
programs directly, i.e. regardless of the current module context:
$ go install filippo.io/mkcert@v1.4.4
go: downloading filippo.io/mkcert v1.4.4
go: downloading golang.org/x/net v0.0.0-20220421235706-1d1ef9303861
go: downloading software.sslmate.com/src/go-pkcs12 v0.2.0
go: downloading golang.org/x/text v0.3.7
go: downloading golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29
For the purposes of this guide you are using a specific version (v1.4.4
). Alternatively,
the special latest
version can be used to install the latest release.
Much like the previous behaviour of go get
, go install
places binaries in $GOPATH/bin
,
or in $GOBIN
if set. See the “Setting up your PATH
“ section in Installing Go to ensure
your PATH
is set correctly.
Verify that mkcert
is now on your PATH
:
$ which mkcert
/home/gopher/go/bin/mkcert
Run mkcert
to check everything is working:
$ mkcert -version
v1.4.4
You can also use go version
to see the module dependencies used in building the program:
$ go version -m $(which mkcert)
/home/gopher/go/bin/mkcert: go1.19.1
path filippo.io/mkcert
mod filippo.io/mkcert v1.4.4 h1:8eVbbwfVlaqUM7OwuftKc2nuYOoTDQWqsoXmzoXZdbc=
dep golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
dep golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 h1:yssD99+7tqHWO5Gwh81phT+67hg+KttniBr6UnEXOY8=
dep golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
dep software.sslmate.com/src/go-pkcs12 v0.2.0 h1:nlFkj7bTysH6VkC4fGphtjXRbezREPgrHuJG20hBGPE=
To eliminate redundancy and confusion, using go get
to build or
install programs is being deprecated in Go 1.16.
Conclusion
That’s it!
As a next step you might like to consider: