Problem: Setting $GOPATH on Mac OSX
When attempting to set the $GOPATH environment variable on Mac OSX, users may encounter the following error: "cannot find package "github.com/#GITHUB_USERNAME#/smitego" in any of: /usr/local/go/src/pkg/github.com/#GITHUB_USERNAME#/smitego (from $GOROOT) ($GOPATH not set)".
Solution:
Since Go version 1.8 (released in February 2017), the GOPATH is automatically determined by the Go toolchain on Mac OSX. It defaults to $HOME/go, which simplifies the initial setup process.
Manual Method for the Shell:
For earlier versions of Go or for a more manual approach, add the following lines to ~/.bash_profile:
export GOPATH=$HOME/go export PATH=$GOPATH/bin:$PATH
Configuring Sublime Text:
For Sublime Text, set the GOPATH in the User settings:
{ "shell": ["/bin/bash"], "env": {"GOPATH": "/Users/#USERNAME#/go/"}, }
Important Note:
When setting GOPATH, always remember to specify the path to the root go directory where src, pkg, and bin reside, not the full path to the specific package.
The above is the detailed content of How do I set the $GOPATH environment variable on Mac OSX for Go?. For more information, please follow other related articles on the PHP Chinese website!