How to Set $GOPATH on macOS for Go Development?

Linda Hamilton
Release: 2024-11-12 14:39:02
Original
467 people have browsed it

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
Copy after login

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/"}
}
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template