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`
相关推荐
hourinX21 小时前
从 v1 到 v2,我重新拆了头像生成的整条链路—— gdenticon 重构日志(二)
go
FungLeo1 天前
成为全栈·Go 后端篇·分类树与标签关系:目录变更为何需要协调
golang·go·gorm·数据库事务·分类树·成为全栈
FungLeo1 天前
成为全栈·Go 后端篇·文章查询与展示投影:安全分页、排序和软删除
golang·go·gorm·分页查询·成为全栈·sql安全
KevinAshen672 天前
用 Go 修复旧下载工具:从接口 403 到凭证截断的完整复盘
go·github
FungLeo3 天前
成为全栈·Go 后端篇·跨语言认证兼容:Node 与 Go 如何互认 JWT 和密码
golang·go·jwt·身份认证·成为全栈·bcrypt
FungLeo3 天前
成为全栈·Go 后端篇·重写之前先锁基线:契约、Node 版本与行为清单
golang·node.js·go·openapi·契约测试·成为全栈
小满zs3 天前
Go语言第十七章(反射)
后端·go
小满zs3 天前
Go语言第十五章(JSON序列化)
后端·go
小满zs3 天前
Go语言第十六章(自定义类型)
后端·go
w-w0w-w3 天前
Go语言学习day1
go