踩坑 Go1.6+ install报错go: go.mod file not found

最近在用go写一个简单的JVM虚拟机,在编译的时候,使用go install,然后命令行提醒

go: go.mod file not found in current directory or any parent directory; see 'go help modules'

当前目录或父目录找不到go.mod文件

只要在你项目源码目录执行下面的命令就可以解决这个问题

go mod init

go会在这个目录下,创建一个go.mod的文件。

再执行go install 就可以成功了