$ GO_PATH is the environment variable that defines where all your Go related things will be, including
- All the libraries you download.
- All project source code.
- All binary files resulting from the source code compilation of your projects.
Notice that this is different from most other languages, which has a folder for each project and saves the files / libraries / binaries in the folder of their respective projects.
See the example file organization from official documentation :
bin/
hello # command executable
outyet # command executable
pkg/
linux_amd64/
github.com/golang/example/
stringutil.a # package object
src/
github.com/golang/example/
.git/ # Git repository metadata
hello/
hello.go # command source
outyet/
main.go # command source
main_test.go # test source
stringutil/
reverse.go # package source
reverse_test.go # test source
golang.org/x/image/
.git/ # Git repository metadata
bmp/
reader.go # package source
writer.go # package source
#... (many more repositories and packages omitted) ...
Now, if you still think you should set the $ GO_PATH to your project folder:
1 - Navigate to the desired folder
2 - Enter the command:
$ echo $PWD >> ~/.bash_profile
$ source ~/.bash_profile
Remember that you will have to do this every time you change the project, since the commands in Go will search everything on the page you set $ GO_PATH