Home >Backend Development >Golang >How to Set $GOPATH on macOS for Go Development?

How to Set $GOPATH on macOS for Go Development?

Linda Hamilton
Linda HamiltonOriginal
2024-11-12 14:39:02468browse

How to Set $GOPATH on macOS for Go Development?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn