Avatar ·

What does the go install command do and how to use it correctly?

Hello everyone! I just started learning Go and am trying to understand the build tools. I read the documentation, but I'm still confused.

\n\n

I wrote a simple program — an HTTP server that is located in the folder ~/projects/myapp/main.go. When I run go build, it creates a binary directly in the current folder. But I heard there is also a command go install. I tried to run it, and it also compiled something, but I didn't find the binary in the project folder. There were no errors in the console. Where did it go?

\n\n

Here is my code:

\n
package main\n\nimport (\n    "fmt"\n    "net/http"\n)\n\nfunc main() {\n    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {\n        fmt.Fprintf(w, "Hello, World!")\n    })\n    http.ListenAnd