Home >Backend Development >Golang >How to Set the $GOPATH Variable Permanently on Mac OSX?
Troubleshooting "Cannot set $GOPATH on Mac OSX"
When attempting to run example code using the command 'smitego-example go run main.go,' an error message indicates that the $GOPATH variable is not set. This article provides a comprehensive guide to setting the $GOPATH variable permanently on Mac OSX.
Solution for Go 1.8 and Later
Starting with Go 1.8, the Go toolchain automatically determines the $GOPATH, setting it to $HOME/go on Mac OSX. This simplifies the process of getting started with Go, allowing users to install packages with 'go get
Manual Method for the Shell
For older versions of Go or for users who prefer manual configuration, the following steps should be followed:
Ensure that the '$' symbol is included where indicated.
Configuration for Sublime Text
Users of Sublime Text can configure the $GOPATH variable as follows:
{ "shell": ["/bin/bash"], "env": {"GOPATH": "/Users/#USERNAME#/go/"}, }
Make sure to replace '#USERNAME#' with your actual username. Ensure that the GOPATH points to the root of your "go" folder (e.g., $HOME/go), not the specific package path.
The above is the detailed content of How to Set the $GOPATH Variable Permanently on Mac OSX?. For more information, please follow other related articles on the PHP Chinese website!