{{tag>[go golang cli programming]}} ====== go ====== Go language toolchain, module management, build, test, and installation notes. ===== Summary ===== ''go'' is the main CLI for building, testing, formatting, and managing Go modules. ===== Install ===== ==== Linux ==== wget https://go.dev/dl/go1.26.4.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.26.4.linux-amd64.tar.gz The tar archive installs Go under ''/usr/local/go''. If an older manual install exists in the same location, clean it up first to avoid mixed files. ===== Config ===== ==== Shell Environment ==== echo 'export GOPATH=$HOME/go' >> ~/.zshrc echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.zshrc The user-provided example used ''$HOME/go/bin'' directly as ''GOPATH'', but the usual layout is ''GOPATH=$HOME/go'' and then add ''$GOPATH/bin'' to ''PATH''. ===== Usage ===== go [arguments] * ''**go** [flags] [arguments]'' * ''**go** mod init module_name'' 새로운 프로젝트 시작. ''go.mod'' 파일 생성. * ''**go** mod tidy'' 실제로 import 하는 패키지를 ''go.mod''에 반영하고 쓰지 않는 의존성을 정리. * ''**go** mod vendor'' 외부 의존성 소스를 프로젝트 내부 ''vendor/'' 디렉토리로 복사. * ''**go** get package_path'' 패키지를 내려받고 ''go.mod''에 추가. * ''**go** get package_path@version'' 특정 버전 지정. * ''**go** run filename.go'' 컴파일 후 즉시 실행. * ''**go** run .'' 현재 모듈 실행. * ''**go** build'' 컴파일. * ''**go** install'' 패키지를 빌드하고 실행 파일을 ''$GOPATH/bin''에 설치. 예: ''go install github.com/zerotymer/package@latest'' * ''**go** test'' ''*_test.go'' 파일을 찾아 테스트 실행. * ''**go** fmt'' Go 표준 스타일로 코드 포맷 정리. * ''**go** vet'' 정적 분석으로 잠재적인 실수를 탐지. * ''**go** version'' 버전 확인. * ''**go** env'' 환경 설정 확인. * ''**go** clean'' 객체 파일과 캐시 삭제. ===== Examples ===== go version go env go mod init example.com/hello go mod tidy go run . go build go test ./... ===== Help ===== ++++ go --help | Go is a tool for managing Go source code. Usage: go [arguments] The commands are: bug start a bug report build compile packages and dependencies clean remove object files and cached files doc show documentation for package or symbol env print Go environment information fix apply fixes suggested by static checkers fmt gofmt (reformat) package sources generate generate Go files by processing source get add dependencies to current module and install them install compile and install packages and dependencies list list packages or modules mod module maintenance work workspace maintenance run compile and run Go program telemetry manage telemetry data and settings test test packages tool run specified go tool version print Go version vet report likely mistakes in packages Use "go help " for more information about a command. Additional help topics: buildconstraint build constraints buildjson build -json encoding buildmode build modes c calling between Go and C cache build and test caching environment environment variables filetype file types goauth GOAUTH environment variable go.mod the go.mod file gopath GOPATH environment variable goproxy module proxy protocol importpath import path syntax modules modules, module versions, and more module-auth module authentication using go.sum packages package lists and patterns private configuration for downloading non-public code testflag testing flags testfunc testing functions vcs controlling version control with GOVCS Use "go help " for more information about that topic. ++++ ===== See Also ===== * [[git]] * [[docker]] * [[syntax:plugins:color]] ===== History ===== * codex:: 2026-06-14 Reorganized the Go page into CLI reference format and added install and shell environment setup notes.