go install

bash 复制代码
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

参考链接:https://go.dev/doc/go-get-install-deprecation

概述

从 Go 1.17 开始,go get不推荐使用安装可执行文件。 go install可以用它来代替。

在 Go 1.18 中,go get将不再构建包;它仅用于添加、更新或删除go.mod.具体来说, go get将始终表现为该-d标志已启用。

用什么代替

要在当前模块的上下文中安装可执行文件,请使用go install不带版本后缀的 ,如下所示。这适用于go.mod当前目录或父目录中文件的版本要求和其他指令。

复制代码
`go install example.com/cmd
`

要安装可执行文件并忽略当前模块,请使用go install 版本 后缀例如@v1.2.3@latest,如下所示。与版本后缀一起使用时,go install不读取或更新go.mod当前目录或父目录中的文件。

复制代码
`# Install a specific version.
go install example.com/cmd@v1.2.3

# Install the highest available version.
go install example.com/cmd@latest`
相关推荐
Mgx1 天前
你知道程序怎样优雅退出吗?—— Go 开发中的“体面告别“全指南
go
光头闪亮亮2 天前
电子发票解析工具-golang服务端开发案例详解
go
资深web全栈开发2 天前
Gin 框架最佳实践:构建可维护的 Go Web 应用
golang·gin
Mgx2 天前
从“CPU 烧开水“到优雅暂停:Go 里 sync.Cond 的正确打开方式
go
GM_8283 天前
从0开始在Go当中使用Apache Thrift框架(万字讲解+图文教程+详细代码)
rpc·go·apache·thrift
Kratos开源社区3 天前
别卷 LangChain 了!Blades AI 框架让 Go 开发者轻松打造智能体
go·agent·ai编程
Kratos开源社区3 天前
跟 Blades 学 Agent 设计 - 01 用“提示词链”让你的 AI 助手变身超级特工
llm·go·agent
百锦再3 天前
第10章 错误处理
java·git·ai·rust·go·错误·pathon
Mgx4 天前
从 4.8 秒到 0.25 秒:我是如何把 Go 正则匹配提速 19 倍的?
go
遥天棋子5 天前
实战PaddleOCR自动识别车位坐标并渲染可点击按钮
go