Go 1.16 的这个新变化需要适应下:go get 和 go install 的变化
生活随笔
收集整理的這篇文章主要介紹了
Go 1.16 的这个新变化需要适应下:go get 和 go install 的变化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文地址:
Go 1.16 的這個新變化需要適應下:go get 和 go install 的變化
一直以來,go get 用于下載并安裝 Go 包、命令等,而 go install 在 module 時代幾乎很少使用,在 GOPATH 年代,go install 用來編譯安裝本地項目。
自 1.16 起,官方說,不應該 go get 下載安裝命令(即可執行程序),不過只是這么說,卻依然可以使用。
但 Go1.17 開始,如果使用 go get 安裝命令,會警告:
$ go get github.com/github/hub
go get: installing executables with 'go get' in module mode is deprecated.To adjust and download dependencies of the current module, use 'go get -d'.To install using requirements of the current module, use 'go install'.To install ignoring the current module, use 'go install' with a version,like 'go install example.com/cmd@latest'.For more information, see https://golang.org/doc/go-get-install-deprecationor run 'go help get' or 'go help install'.
也就是說,go get 只用來下載普通的包,安裝可執行程序,應該使用 go install。
$ go install github.com/github/hub
這會將 hub 命令安裝到 $GOBIN 下。
此外,go get 有一個參數 -d,指示 go get 下載對應的包,但不做編譯和安裝。將來的版本,-d 會成為默認行為,這樣會更快。此外,因為不編譯,即使目標依賴在特定平臺編譯報錯,go get 也能正常執行完。
關于 Go 1.16 的變化。Reddit 上有一張圖總結的挺好的:
總結
以上是生活随笔為你收集整理的Go 1.16 的这个新变化需要适应下:go get 和 go install 的变化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: swig error : Unrecog
- 下一篇: 2022-2028年中国智慧物流行业深度