Description

Unable to install gin on go v.1.19.1

How to reproduce

$ go get -u github.com/gin-gonic/gin

'go get' is no longer supported outside a module. To build and install a command, use 'go install with a version, like 'go install example.com/cmd@latest'

$ go install github.com/gin-gonic/gin

'go install' requires a version when current directory is not in a module. Try 'go install github.com/gin-gonic/gin@latest' to install the latest version

$ go install github.com/gin-gonic/gin@latest

package github.com/gin-gonic/gin is not a main package

Environment

  • go version: go1.19.1 darwin/amd64
  • gin version (or commit ref):
  • operating system: macOS 12.4

Comment From: brett--anderson

Did you find a solution to this? I'm having the same issues

Comment From: lwlshawn

In the project directory, run the command "go mod init" first, and then try the commands again; this resolved the issue for me.

Comment From: brett--anderson

Thanks for the response! Ultimately I was installing gin like this as a build step in a Docker file and removing it broke nothing (I guess the application ultimately specifies that it needed gin installed as a dependency)

Comment From: Oleksandr1902

I went to https://gin-gonic.com/docs/quickstart/ I've solved this by running: go get -u github.com/gin-gonic/gin

Comment From: Mark24Code

same

Comment From: Swapnil27012000

$ go install github.com/gin-gonic/gin@latest package github.com/gin-gonic/gin is not a main package

Solution: 1] go mod init example.com/m/v2 2] go mod tidy Done.

Comment From: marcsheen

I was having the same problem. I of course already had the mod file setup with go mod init and running it again just said that, and running go mod tidy did nothing. So, I removed the @latest tag and it worked! Don't know why. But if someone is having the same issue with "is not the main package" and have already run go mod init, try running the install command without the "@latest" in the end. It worked for the version v1.10.0 for me.