Understanding the Differences Between go get and go install
While exploring the Go programming tool, you might have observed that go get performs multiple operations, including downloading, compiling, and installing software, while go install only compiles and installs. You might wonder why go install exists since go get seems to offer a more comprehensive solution.
Purpose of go install
go install plays a crucial role in the local development workflow. Consider a scenario where you want to utilize a library, but require modifications. In such a case, you would typically follow these steps:
go get lacks flags to prevent downloading, making it unsuitable for this workflow.
Similar Workflow for Developing Custom Packages
The same workflow is applicable when developing a new package from scratch. You would download the package's dependencies using go get -d, make necessary modifications, and then install the custom package using go install.
Recent Updates in Go 1.16
In Go 1.16, the usage of go install and go get has been updated and clarified. go install is now the recommended way to build and install packages in module mode. go get should be used with the -d flag to adjust module dependencies without building packages. The use of go get for building and installing packages is deprecated. Future releases will enable the -d flag by default.
The above is the detailed content of Go get vs. go install: When Should I Use Which?. For more information, please follow other related articles on the PHP Chinese website!