安装好 go 后, 在命令行输入 go 命令会输出一系列 go 命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
➜  ~ go
Go is a tool for managing Go source code.

Usage:

	go <command> [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         update packages to use new APIs
	fmt         gofmt (reformat) package sources
	generate    generate Go files by processing source
	get         download and install packages and dependencies
	install     compile and install packages and dependencies
	list        list packages or modules
	mod         module maintenance
	run         compile and run Go program
	test        test packages
	tool        run specified go tool
	version     print Go version
	vet         report likely mistakes in packages

go install 命令的功能是 compile and install packages and dependencies.

它能将 go package 编译并生成可执行文件到 $GOPATH/go/bin 目录下, 将此目录添加到 $PATH 环境变量中, 就能通过命令行直接访问.

present 为例:

假设 present 包已下载到 $GOPATH/go/src/golang.org/x/tools/cmd/ 目录下.

在命令行运行:

go install ~/go/src/golang.org/x/tools/cmd/present

此后, ~/go/bin 目录下多了一个名为 present 文件.

由于 ~/go/bin 目录已在 $PATH 中, 所以可以直接在命令运行 present 命令.

1
2
➜  ~ present
2019/06/26 02:09:36 Open your web browser and visit http://127.0.0.1:3999

REF