Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should you set the $GOPATH variable? [duplicate]

Can anyone explain when to set $GOPATH? I know it's in the default, C:\Users\Username\go, location, but what if all my coding projects live in Z:<codelocation> ?

like image 400
Justin Reddick Avatar asked May 07 '26 06:05

Justin Reddick


1 Answers

From the documentation:

The Go path is used to resolve import statements.

The GOPATH environment variable lists places to look for Go code.

When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).

Assuming you're using modules, which you probably should be, the setting of GOPATH will not impact your projects regardless of where you put them. It only needs to be set somewhere so the Go tools have a cache to store libraries and binaries.

like image 182
Hymns For Disco Avatar answered May 10 '26 09:05

Hymns For Disco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!