How can I install a specific version of golint for use globally?

5.6k views Asked by At

I'm trying to create a docker image for use in a build pipeline that has various tools pre-installed for building and testing go projects. One tool we need is golint but I'm struggling to see how to install a specific version of it. The reason I want to lock down the version is to avoid accidental / unwanted / unintended breakages at a later date.

For a start, looking here the versions are not exactly in an easy-to-type format.

Also when I try to use the following command

go get -u golang.org/x/lint/[email protected]

I get an error

go: cannot use path@version syntax in GOPATH mode

Googling has so far yielded very few relevant results...

Is what I'm trying to do possible? Many thanks!

1

There are 1 answers

0
viswajithiii On

You need to be in go module mode to get code of a specific version, since in addition to downloading the code, the version is recorded in the go module file.

The easiest way to do this would be to create an empty directory, run go mod init, which will create a go.mod file.

Then, you can run go get golang.org/x/lint/[email protected], which will add golint at that version to your go.mod file. You can then run go install golang.org/x/lint/golint from within that directory, which will install golint at the version specified into your $GOBIN directory (which defaults to $GOPATH/bin).