Avatar ·

How to install a package in Go via go get: command not working or deprecated?

Hello everyone! I just started learning Go, and I have a problem with installing third-party packages. I read old articles where everyone simply wrote go get github.com/some/package, and the package was immediately downloaded to $GOPATH. But I have Go 1.16+, and the go get command behaves strangely.

\n\n

Here's what I'm doing. I have a simple project in the folder /home/user/myproject:

\n\n
// main.go\npackage main\n\nimport "github.com/gin-gonic/gin"\n\nfunc main() {\n    r := gin.Default()\n    r.GET("/", func(c *gin.Context) {\n        c.JSON(200, gin.H{"message": "hello"})\n    })\n    r.Run()\n}\n
\n\n

I run go get github.com/gin-gonic/gin, but in the console I see a warning:

\n\n
go: 'go get' is not a standard com