Go命令基础之go install

一 简介

1、用于编译并安装代码包或源码文件。
2、安装代码包会在当前工作区的pkg/<平台相关目录>下生成归档文件。
3、安装命令源码文件会在当前工作区的bin目录或$GOBIN目录下生成可执行文件。
4、执行该命令且不追加任何参数时,它会试图把当前目录作为代码包并安装。
5、执行该命令且以代码包的导入路径作为参数时,该代码包及其依赖会被安装。
6、执行该命令且以命令源码文件及其库源码文件作为参数时,只有这些文件会被编译并安装。
 
二 实战
  1. [root@localhost ds]# ls
  2. showds.go
  3. [root@localhost ds]# go install
  4. [root@localhost ds]# ls
  5. showds.go
  6. [root@localhost ds]# ls $GOBIN
  7. ds
  8. [root@localhost ds]# cd ../../pkgtool/
  9. [root@localhost pkgtool]# go install
  10. go install: no install location for directory /root/goc2p/src/pkgtool outside GOPATH
  11. For more details see:'go help gopath'
  12. [root@localhost pkgtool]# export GOPATH=$GOPATH:~/goc2p
  13. [root@localhost pkgtool]# go install
  14. [root@localhost pkgtool]# ls
  15. envir.go envir_test.go fpath.go ipath.go pnode.go util.go util_test.go
  16. [root@localhost pkgtool]# cd ~/goc2p/
  17. [root@localhost goc2p]# cd pkg
  18. [root@localhost pkg]# ds
  19. /root/goc2p/pkg:
  20. linux_amd64/
  21. pkgtool.a

猜你喜欢

转载自cakin24.iteye.com/blog/2391024