php editor Zimo will introduce to you the use of the "go get" and "go install" commands in the Go language on the go.sum file. In Go language projects, the go.sum file is used to record the packages and their version information that the project depends on, ensuring the stability and consistency of the project during the build and deployment process. By understanding the impact of the "go get" and "go install" commands on the go.sum file, you can better manage and control project dependencies and improve development efficiency and code quality. Let us learn the specific usage of these two commands together!
I am using go 1.20.3
I just installed this package using go get and go install
go get -v github.com/mactsouk/go/simplegithub go install github.com/mactsouk/go/simplegithub
My go.sum file contains:
github.com/mactsouk/go v0.0.0-20180603081621-6a282087f7bd h1:tqjgx/jaxlj3rnl7ps7xzqlvth8rl/dusa8wpe9w4y0= github.com/mactsouk/go v0.0.0-20180603081621-6a282087f7bd/go.mod h1:trtlpc1xi1zoqdba/cixgds+fcaizdqupmrflet5dbi=
go.mod file is:
module calculator go 1.20 require github.com/mactsouk/go v0.0.0-20180603081621-6a282087f7bd // indirect
On my $home/go/pkg/mod/github.com/mactsouk/ aod
dr-xr-xr-x 5 user staff 160 jul 4 18:42 [email protected]
$home/go/bin/, only two files. Why does go install not copy the binary files of the simplegithub module?
drwxr-xr-x 4 user staff 128 Jun 26 23:37 . drwxr-xr-x 4 user staff 128 Jun 26 23:35 .. -rwxr-xr-x 1 user staff 3410064 Jun 26 23:35 go-outline -rwxr-xr-x 1 user staff 28237216 Jun 26 23:37 gopls
Is there a difference between go get and go install? Why do I have this module file twice on go.sum?
go get and go install
The go get and go install commands in Go have different purposes:
go get is used to retrieve and download packages and their dependencies from a remote repository. It updates the go.mod and go.sum files with the version of the downloaded package. If the package already exists, go get will update it to the latest version.
go install Compile and install the package in the project's GOPATH or GOBIN. It does not update the go.mod or go.sum files. Instead, it uses the information in these files to determine the correct version of the dependency to use.
In your case, when you run go get, it downloads and installs the package github.com/mactsouk/go/simpleGitHub and its dependencies. This action updates the go.mod and go.sum files with the version of the downloaded package.
When you subsequently run go install on the same package, you do not need to download the package again because it is already present in the local Go module cache. Therefore, go install uses the existing package and its version in the cache and does not modify the go.mod or go.sum files.
The reason you see this module listed twice in the go.sum file is that it contains the module version (v0.0.0-20180603081621-6a282087f7bd) and its corresponding go.mod file, which Contains checksum. This is expected behavior and ensures dependency integrity.
In summary, go get and go install have different purposes. It is normal for modules to be repeated in the go.sum file.
The above is the detailed content of go get and go install on the go.sum file. For more information, please follow other related articles on the PHP Chinese website!