HomeToolsAbout a20k

Run and Build

Running Go File/Packages

run compiles then runs a main package comprised of the .go files.

  • The command is compiled to a temporary folder.
# compile and run the go package go run main.go

Compile

install and build compiles the files into binaries.

# compile the packages named by imports, along with dependencies, but doesn't install the results go build file_path # compiles and installs the packages named by the imports go install file_path

go download vs go build

go mod download is downloading all of the modules in the dependency graph, which it can determine from reading only the go.mod files. It doesn't know which of those modules are actually needed to satisfy a build, so it doesn't pull in the checksums for those modules.

go mod tidy has to walk the package graph in order to ensure that all imports are satisfied. So it knows, for a fact, without doing any extra work, that the modules it walks through are needed for a go build in some configuration.

© VincentVanKoh