Go CLI Modules and Workspaces

Go modules and go work workflows for init, tidy, vendor, replace, workspaces, private modules, and dependency management.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Modules Basics

Modules Basics commands and patterns for the Go command.

Initialize module

Create a new go.mod for the current project.

bashANYgomodinit
bash
go mod init example.com/myapp
Notes

Create a new go.mod for the current project. Useful in Go CLI workflows.

Tidy dependencies

Add missing and remove unused module requirements.

bashANYgomodtidy
bash
go mod tidy
Notes

Add missing and remove unused module requirements. Useful in Go CLI workflows.

Download dependencies

Pre-fetch required modules into the module cache.

bashANYgomoddownload
bash
go mod download
Notes

Pre-fetch required modules into the module cache. Useful in Go CLI workflows.

Print module graph

Show the module dependency graph.

bashANYgomodgraph
bash
go mod graph
Notes

Show the module dependency graph. Useful in Go CLI workflows.

Explain dependency

Show why a package or module is needed.

bashANYgomodwhy
bash
go mod why -m github.com/pkg/errors
Notes

Show why a package or module is needed. Useful in Go CLI workflows.

Editing and Replacements

Editing and Replacements commands and patterns for the Go command.

Add replace directive

Point a module dependency to a local checkout.

bashANYgomodreplace
bash
go mod edit -replace example.com/lib=../lib
Notes

Point a module dependency to a local checkout. Useful in Go CLI workflows.

Add require directive

Add an explicit module requirement.

bashANYgomodrequire
bash
go mod edit -require example.com/lib@v1.2.3
Notes

Add an explicit module requirement. Useful in Go CLI workflows.

Set go line

Set the minimum Go version in go.mod.

bashANYgomodgo-version
bash
go mod edit -go=1.25
Notes

Set the minimum Go version in go.mod. Useful in Go CLI workflows.

Vendor dependencies

Copy dependencies into a vendor directory.

bashANYgomodvendor
bash
go mod vendor
Notes

Copy dependencies into a vendor directory. Useful in Go CLI workflows.

Inspect current module JSON

Inspect current module metadata.

bashANYgolistmodule
bash
go list -m -json
Notes

Inspect current module metadata. Useful in Go CLI workflows.

Dependency Updates

Dependency Updates commands and patterns for the Go command.

Upgrade dependency

Update a dependency to the latest version.

bashANYgogetupgrade
bash
go get example.com/lib@latest
Notes

Update a dependency to the latest version. Useful in Go CLI workflows.

Upgrade patch release

Update a dependency within its compatible patch/minor range.

bashANYgogetupgrade
bash
go get -u=patch ./...
Notes

Update a dependency within its compatible patch/minor range. Useful in Go CLI workflows.

List available updates

Show modules that have newer versions available.

bashANYgolistupdates
bash
go list -m -u all
Notes

Show modules that have newer versions available. Useful in Go CLI workflows.

Verify module cache

Verify dependencies in module cache against go.sum.

bashANYgomodverify
bash
go mod verify
Notes

Verify dependencies in module cache against go.sum. Useful in Go CLI workflows.

Exclude bad version

Exclude a dependency version from selection.

bashANYgomodexclude
bash
go mod edit -exclude example.com/lib@v1.2.4
Notes

Exclude a dependency version from selection. Useful in Go CLI workflows.

Private Modules

Private Modules commands and patterns for the Go command.

Set GOPRIVATE

Mark private module path patterns.

bashANYgoprivategoprivate
bash
go env -w GOPRIVATE=github.com/myorg/*
Notes

Mark private module path patterns. Useful in Go CLI workflows.

Set GONOPROXY

Bypass proxy for selected module path patterns.

bashANYgoprivategoproxy
bash
go env -w GONOPROXY=github.com/myorg/*
Notes

Bypass proxy for selected module path patterns. Useful in Go CLI workflows.

Set GONOSUMDB

Skip checksum database for selected private modules.

bashANYgoprivatesumdb
bash
go env -w GONOSUMDB=github.com/myorg/*
Notes

Skip checksum database for selected private modules. Useful in Go CLI workflows.

Control allowed VCS

Restrict version control systems used for module fetches.

bashANYgoprivatevcs
bash
go env -w GOVCS=github.com:git,private:all
Notes

Restrict version control systems used for module fetches. Useful in Go CLI workflows.

Workspaces

Workspaces commands and patterns for the Go command.

Initialize workspace

Create a go.work file for multiple local modules.

bashANYgoworkworkspace
bash
go work init
Notes

Create a go.work file for multiple local modules. Useful in Go CLI workflows.

Add module to workspace

Add one or more modules to go.work.

bashANYgoworkworkspace
bash
go work use ./app ./lib
Notes

Add one or more modules to go.work. Useful in Go CLI workflows.

Print go.work JSON

Inspect go.work configuration as JSON.

bashANYgoworkjson
bash
go work edit -json
Notes

Inspect go.work configuration as JSON. Useful in Go CLI workflows.

Sync workspace build list

Sync workspace dependencies back to module go.mod files.

bashANYgoworksync
bash
go work sync
Notes

Sync workspace dependencies back to module go.mod files. Useful in Go CLI workflows.

Recursively add modules

Add modules under a tree recursively.

bashANYgoworkworkspace
bash
go work use -r .
Notes

Add modules under a tree recursively. Useful in Go CLI workflows.

Recommended next

No recommendations yet.