DEV Community

tdev
tdev

Posted on

The error I encountered when setting up writefreely

Purpose of This Article

The setup process for WriteFreely is documented here, but following the steps resulted in an error. This article provides a solution for resolving the error.

Error Description

When running the go get command according to the Quick start guide, the following error occurs:

go get -d github.com/writefreely/writefreely/cmd/writefreely

go: go.mod file not found in the 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'.
Enter fullscreen mode Exit fullscreen mode

Cause of the Error

When using a relatively new version of Go, dependency management is performed using Go Modules instead of the $GOPATH way. You can choose between $GOPATH or Go Modules with the GO111MODULE setting. However, the behavior can be quite complex and varies depending on the Go version, as described in the following article:

https://maelvls.dev/go111module-everywhere/

With newer versions of Go, Go Modules have become mandatory, and go get can no longer be used without Go Modules.

Solution

You can set GO111MODULE to auto as follows to make it behave like the old $GOPATH-based approach:

go env -w GO111MODULE=auto
Enter fullscreen mode Exit fullscreen mode

After running the above command, you can execute go get -d github.com/writefreely/writefreely/cmd/writefreely, and it will download the source code to $GOPATH/src. If your $GOPATH is not set, you can navigate to $HOME/go/src/github.com/writefreely/writefreely.

Other Notes

  • In my environment, echo $GOPATH does not show a value. However, go env GOPATH shows a value. It seems that in recent versions of Go, there is no need to explicitly set $GOPATH in files like .zshrc.

https://stackoverflow.com/questions/21001387/how-do-i-set-the-gopath-environment-variable-on-ubuntu-what-file-must-i-edit/53026674#53026674

  • When using the $GOPATH approach with go get, the source code is downloaded to $GOPATH/src/. But when using Go Modules with go get, it is downloaded to $GOPATH/pkg/mod.

https://stackoverflow.com/questions/66284870/go-get-not-downloading-to-src-folder

Top comments (0)