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`
相关推荐
basketball6167 分钟前
Go语言介绍
开发语言·go
10ms指针18 小时前
【高性能Go实践02】深水区重构:规避 sync.Pool 大对象缺陷与 Cgo 边界内存安全实践
go
鹏北海2 天前
Go 语言基础笔记 — 面向 JS/TS 前端开发者
go
鹏北海2 天前
Go 语言进阶笔记 — 面向 JS/TS 前端开发者
go
鹏北海2 天前
Go 包管理笔记 — 面向 JS/TS 前端开发者
go
百度Geek说2 天前
告别死锁和陈旧语法、告别性能瓶颈:新手Gopher 秒变 Go 语言大神
人工智能·go
用户398346161202 天前
Go-Spring 实战第 14 课 —— Bean 注册函数:Provide、Module、Group 以及 Configuration
spring·go
锋行天下3 天前
一句mysql复杂查询搞崩一个壮汉
后端·mysql·go
用户398346161203 天前
Go-Spring 实战第 13 课 —— Bean 元信息:名称、生命周期、接口导出、条件和显式依赖
spring·go
猪猪拆迁队3 天前
用 ESP32-S3 和 TinyGo,先搭个 AI 语音助手的小底座
前端·后端·go