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`
相关推荐
里海_go1 天前
Go 语言内存管理机制详解
go
斐波那契数列2 天前
没有 JSX,也能在 Go 里写 React 风格 GUI:Tenon 的架构与性能实践
go
花椒技术2 天前
花椒语音房联机五子棋:Go 服务端如何保证一回合只落一颗子
websocket·go
Sailing2 天前
🚀客户端都超时了,你的 Go 服务还在查库?Context 取消链路不打通,连接池迟早被打爆
后端·面试·go
小满zs2 天前
Go语言第二十一章(Gin上传文件)
后端·go
我不会起名字3223 天前
Agent 总调错工具?MCP 接进 Go 后端的 4 个约束
后端·go·agent·mcp
我不会起名字3225 天前
WebSocket 停机与在线状态:Shutdown 返回后还需要清理什么
redis·后端·websocket·go·即时通讯·im·故障排查
小满zs5 天前
Go语言第二十章(初探Gin)
后端·go
小满zs5 天前
Go语言第十九章(http标准库)
后端·go
我不会起名字3226 天前
仅 Web 主动 ping:30 秒读超时与各平台保活
前端·后端·websocket·go·即时通讯·im·故障排查