go install @latest found but does not contain package

Viewed 1998

I'm trying to install my package using go install but I get this error message when running the command go install github.com/JoaoDanielRufino/gcloc/cmd/gcloc@latest:

go install: github.com/JoaoDanielRufino/gcloc/cmd/gcloc@latest: module github.com/JoaoDanielRufino/gcloc@latest found (v1.0.0), but does not contain package github.com/JoaoDanielRufino/gcloc/cmd/gcloc

I want the executable name to be gcloc.

Here is the current source code: https://github.com/JoaoDanielRufino/gcloc

Note: I've already tried go clean -modcache but it didn't work

2 Answers

As the main function of this package isn't on its root, you should pass the directory of the main package on your command.

So, your command will be: go install -v github.com/JoaoDanielRufino/gcloc/cmd@latest

I came across a similar issue when I was trying to use go install to install the cloudflare/cf-terraforming tool on my machine. The documentation for this tool is not clear on the installation and I had to dig around to get this to work

Basically @Jictyvoo answer above sums it up, if the path is pointing to anything other than directory where the main.go file is sitting I got the error

Command: go install github.com/cloudflare/cf-terraforming@latest v0.8.0@latest

go: github.com/cloudflare/cf-terraforming@latest: module github.com/cloudflare/cf-terraforming@latest found (v0.8.0), but does not contain package github.com/cloudflare/cf-terraforming

when I switched to the below it worked fine for me: Command: go install -v github.com/cloudflare/cf-terraforming/cmd/cf-terraforming@latest

This worked for me after checking the repo and realising that the main.go file was sitting in the cmd/cf-terraforming subdirectory

Related