$GO_PATH is the enviroment variable that defines where all your things related to Go will be, including
- All bilbiotecas you download.
- All project source code.
- All binary files resulting from the compilation of your projects' source code.
Note that this is different from most languages, which have a folder for each project and store the/libraries/binaries in the folder of their respective projects.
See the example of file organization taken 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 find it best to set $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 your project, as the Go commands will look for everything on the page you set $GO_PATH
Type in the terminal
go env
and put the result...– navossoc