Setting $GOPATH on Mac OSX
Problem Statement:
When attempting to run Go example code, an error is encountered indicating that the GOPATH environment variable is unset.
Solution:
For the Shell:
Ensure that your ~/.bash_profile file includes the following lines:
export GOPATH=$HOME/go export PATH=$GOPATH/bin:$PATH
Note: Use "$" symbols only at the appropriate places as shown.
For Sublime Text:
Add the following JSON to the file:
{ "shell": ["/bin/bash"], "env": {"GOPATH": "/Users/#USERNAME#/go/"}, }
Replace "#USERNAME#" with your actual username.
Important Note:
As of Go 1.8 (released Feb 2017), the GOPATH is automatically determined by the Go toolchain. It defaults to $HOME/go on Mac OSX. This simplifies the setup process and allows you to start using Go immediately.
The above is the detailed content of How to Set GOPATH on Mac OSX?. For more information, please follow other related articles on the PHP Chinese website!