go install
将编译的中间文件放在 GOPATH 的 pkg 目录下,以及固定地将编译结果放在 GOPATH 的 bin 目录下。
go install的编译规律:
- go install 是建立在 GOPATH 上的,无法在独立的目录里使用 go install。
- GOPATH 下的 bin 目录放置的是使用 go install 生成的可执行文件,可执行文件的名称来自于编译时的包名。
- go install 输出目录始终为 GOPATH 下的 bin 目录,无法使用-o附加参数进行自定义。
- GOPATH 下的 pkg 目录放置的是编译期间的中间文件。
示例:
通过gopm get -g github.com/xxx
下载golang包时,往往没有安装。在$GOPATH/bin
看到相应的可执行文件。比如cobra、 protoc-gen-go、protoc-gen-gogofaster等。
以下载 && 安转 https://github.com/gogo/protobuf/tree/master/protoc-gen-gogofast
为例:
gopm get -g github.com/gogo/protobuf/tree/master/protoc-gen-gogofast
- cd $GOPAHT/src/github.com/gogo/protobuf/tree/master/protoc-gen-gogofast
- go install
命令执行之后,就可以在$GOPATH/bin
下看到可执行文件protoc-gen-gogofast