Go1.6+ install Error: go: go.mod file not found [How to Solve]

Recently, I was writing a simple JVM virtual machine with go. When compiling, I used go install, and then the command line reminded me

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

The go.mod file cannot be found in the current directory or parent directory

Just execute the following command in your project source directory to solve this problem

go mod init

Go will create a go.mod file in this directory.

Then execute go install to succeed

Similar Posts: