Install the latest stable Go on Windows; the installer sets GOROOT and PATH
winget install GoLang.GoSet up Go: install on Windows, Linux and macOS, configure GOPROXY and checksum services, GOROOT/GOPATH, module projects, cross-compilation and common error fixes.
Install the latest stable Go on Windows; the installer sets GOROOT and PATH
winget install GoLang.GoUse Homebrew on macOS and unpack the official tarball into /usr/local/go on Linux
# macOS
brew install go
# Ubuntu / Debian(用官方包,发行版源版本偏旧)
wget https://go.dev/dl/go1.22.6.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.6.linux-amd64.tar.gzAdd /usr/local/go/bin to PATH after unpacking
Check the Go version used by the CLI
go version
go env GOVERSIONInstall several Go versions side by side with the official dl tool and call them by versioned prefix
go install golang.org/dl/go1.21.13@latest
go1.21.13 downloadInstall the aggregated linter instead of assembling individual linters
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latestSwitch the module proxy and checksum database; the single most important step for downloads in China
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOSUMDB=sum.golang.google.cnBypass the public proxy and checksum for private repositories
go env -w GOPRIVATE=git.example.com/*
go env -w GONOSUMDB=git.example.com/*Disable checksum verification when the intranet cannot reach the checksum service
go env -w GONOSUMCHECK=1
go env -w GOSUMDB=offDisabling checks weakens supply-chain safety; only do this on a fully controlled intranet
Route go commands through a proxy while excluding intranet hosts
go env -w HTTPS_PROXY=http://127.0.0.1:7890
go env -w NO_PROXY=localhost,127.0.0.1,git.example.comRemove a value written by go env -w and fall back to the default
go env -u GOPROXYShow the SDK root, workspace directory and binary output directory
go env GOROOT GOPATH GOBINGOPATH defaults to ~/go; binaries from go install land in GOPATH/bin
Add GOPATH/bin to PATH or commands installed with go install will not be callable
# Windows(永久生效)
setx PATH "%PATH%;%USERPROFILE%\go\bin"
# macOS / Linux
echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.zshrcSet a custom binary output directory to keep tools in one place
go env -w GOBIN=C:\tools\binPin module behavior so builds do not fail on a read-only go.mod
go env -w GOFLAGS=-mod=modInitialize a module; the module path becomes the import prefix
mkdir demo && cd demo
go mod init github.com/you/demoTidy dependencies and run the current package
go mod tidy
go run .Compile a single binary and run it; no runtime needed on the target host
go build -o bin/app .
./bin/appCross-compile for Linux; on Windows assign environment variables first
# Windows 构建 Linux 产物
$env:GOOS="linux"; $env:GOARCH="amd64"; go build -o app .
# macOS / Linux
GOOS=linux GOARCH=amd64 go build -o app .Run all tests plus the official vet checks
go test ./...
go vet ./...Inspect the module graph to see which dependency bumped a version
go mod graph | grep ginInstall the official Go extension; the first open prompts to install gopls and friends
code --install-extension golang.goInstall the language server manually; retry with GOPROXY set when the proxy is restricted
go install golang.org/x/tools/gopls@latestInstall Delve, which the VS Code Go debugger depends on
go install github.com/go-delve/delve/cmd/dlv@latestInstall GoLand on Windows; use brew --cask goland on macOS
winget install JetBrains.GoLandWhen go is not found, check that PATH contains the Go bin directory; reopen the terminal on Windows
# Windows
where go
# macOS / Linux
which -a goSwitch the proxy, clear the module cache and download again when timeouts occur
go env -w GOPROXY=https://goproxy.cn,direct
go clean -modcache
go mod downloadFind out which import chain pulls in a dependency
go mod why -m github.com/gin-gonic/ginStop Go from auto-downloading a newer toolchain, which stalls offline build machines
go env -w GOTOOLCHAIN=localClear build and test caches when results look stale
go clean -cache -testcacheLocate the process holding the port when startup reports it is already in use
netstat -ano | findstr :8080This website uses cookies to ensure you get the best experience on our website. Privacy Policy.