Installation from source
-
验证是否已安装 Go 1.16+
$ go version
如果
go
未安装,请按照上的说明操作the Go website. -
克隆此存储库
$ git clone https://github.com/cli/cli.git gh-cli $ cd gh-cli
-
构建和安装
Unix-like systems
# installs to '/usr/local' by default; sudo may be required $ make install # or, install to a different location $ make install prefix=/path/to/gh
Windows
# build the `bin\gh.exe` binary > go run script\build.go
Windows 上没有可用的安装步骤。
-
跑
gh version
检查它是否有效。Windows
跑
bin\gh version
检查它是否有效。
Cross-compiling binaries for different platforms
您可以使用安装了 Go 的任何平台,来构建用于其他平台或 CPU 体系结构的二进制文件。这是通过设置环境变量(如 GOOS 和 GOARCH)实现的。
例如,编译gh
—— 32 位 Raspberry Pi 操作系统的二进制文件:
# on a Unix-like system:
$ GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 make clean bin/gh
# on Windows, pass environment variables as arguments to the build script:
> go run script\build.go clean bin\gh GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0
运行go tool dist list
,列出所有支持的 GOOS/GOARCH 值。
提示:要减小生成的二进制文件的大小,可以使用GO_LDFLAGS="-s -w"
。这将忽略用于调试的符号表。请参阅supported linker flags.