Setting $GOPATH on Mac OSX
Running certain Go applications may trigger an error indicating an unset $GOPATH variable. To resolve this, proper configuration of $GOPATH is crucial for successful execution.
Manual Configuration
For permanent system-wide configuration, modify your ~/.bash_profile file. Add the following lines:
export GOPATH=$HOME/go export PATH=$GOPATH/bin:$PATH
Sublime Text
For Sublime Text users, navigate to: Sublime Text Menu > Preferences > Package Settings > GoSublime > Settings: User.
Update the env section as follows:
{ "env": {"GOPATH": "/Users/#USERNAME#/go/"} }
Automatic Configuration for Go 1.8 and Later
As of Go 1.8, GOPATH is automatically determined by the Go toolchain. It defaults to $HOME/go on macOS, eliminating the need for manual configuration.
Note that the GOPATH should point to the root of your Go folder where src, pkg, and bin reside, not the full path of any specific package within your GOPATH.
The above is the detailed content of How to Set $GOPATH on macOS for Go Development?. For more information, please follow other related articles on the PHP Chinese website!