Open dushaoshuai opened 1 year ago
go install github.com/mikefarah/yq/v4@v4.26.1
之前一直没搞明白,go install github.com/mikefarah/yq/v4@v4.26.1 中的 v4 代表什么,一度以为是该项目的 v4 分支。现在看来,是自己对 Go 的模块管理理解不到位。
v4
在 yq 项目中,v4 分支 的 go.mod 文件中,module 指令行内容为:
module github.com/mikefarah/yq/v4
而在 v3 分支 的 go.mod 文件中,module 指令行内容为:
module github.com/mikefarah/yq/v3
可见,该项目升级 major 版本时,模块路径也会改变。这也是 Go 规范中所期望的行为^1。go-redis 也是这么做的^2。
所以,v4 是模块路径的一部分。
指定版本有两种形式,在模块路径后加 @,再加 latest 或者具体版本号^3。
@
latest
如在 go install github.com/mikefarah/yq/v4@v4.26.1 中,github.com/mikefarah/yq/v4 是模块路径,v4.26.1 是版本号。如果是 go install github.com/mikefarah/yq/v4@latest,则是安装最新版本。
github.com/mikefarah/yq/v4
v4.26.1
go install github.com/mikefarah/yq/v4@latest
go help install
go help packages
go help importpath
go install github.com/mikefarah/yq/v4@v4.26.1
之前一直没搞明白,
go install github.com/mikefarah/yq/v4@v4.26.1
中的v4
代表什么,一度以为是该项目的 v4 分支。现在看来,是自己对 Go 的模块管理理解不到位。在 yq 项目中,v4 分支 的 go.mod 文件中,module 指令行内容为:
而在 v3 分支 的 go.mod 文件中,module 指令行内容为:
可见,该项目升级 major 版本时,模块路径也会改变。这也是 Go 规范中所期望的行为^1。go-redis 也是这么做的^2。
所以,
v4
是模块路径的一部分。如何指定版本
指定版本有两种形式,在模块路径后加
@
,再加latest
或者具体版本号^3。如在
go install github.com/mikefarah/yq/v4@v4.26.1
中,github.com/mikefarah/yq/v4
是模块路径,v4.26.1
是版本号。如果是go install github.com/mikefarah/yq/v4@latest
,则是安装最新版本。See also
go help install
go help packages
go help importpath