Home >Backend Development >Golang >What's the Difference Between `go build` and `go install` in Go?
The Go documentation doesn't explain the difference between go build and go install in detail. One might expect install to follow the make install pattern—that it takes the compiled artifacts and places them in their final designated location. However, in the case of go install, it places them in GOROOT/bin instead.
go build solely compiles the executable file and moves it to the specified destination. On the other hand, go install performs additional tasks:
The cached dependencies are then utilized in subsequent compilations, provided the source code remains unchanged.
To illustrate the outcomes of using go build and go install:
├── bin │ └── hello # by go install └── src └── hello ├── hello # by go build └── hello.go
Note: go build generates the executable file within the current directory, while go install places it in $GOPATH/bin.
For more detailed information and advanced functionalities, refer to the official Go documentation: [https://go.dev/doc/install/troubleshooting#how-go-install-works](https://go.dev/doc/install/troubleshooting#how-go-install-works)
The above is the detailed content of What's the Difference Between `go build` and `go install` in Go?. For more information, please follow other related articles on the PHP Chinese website!