Hello, I’m currently setting up Golang for my machine because I’m taking a Go course. The part I’m having trouble with is setting GOPATH equal to where I want my Go directory to be at (which is within a Projects subdirectory). I’m on a Mac/Unix for reference. I’ve tried editing both .bash_profile and .bashrc to read
I’ve even tried placing the line inside of a zsh file. None seem to work for me. I wonder if maybe I am editing them under the wrong parent directory. When I do go env it still has GOPATH under the location where I installed Golang.
I think going through this link will help.
Basically you need to put this line in .bashrc
export GOPATH=$(go env GOPATH)
Have you restarted your shell after you changed your RC files?
In general though I’d strongly suggest to not care for
GOPATH projects anymore. Only use go modules.
GOPATH can set many dir, example
export GOPATH="/root/go:/data/go" in linux
Thanks, my Instructor told me that as well.
I still had no luck setting GOPATH = to my go workspace.
I guess it will not be needed for Go Modules?
GOPATH is mostly for legacy projects and to
go install binaries.
go build within a go module, the
GOPATH is not necessary.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.