How do I set the $GOPATH environment variable on Mac OSX for Go?

Barbara Streisand
Release: 2024-11-21 14:52:12
Original
697 people have browsed it

How do I set the $GOPATH environment variable on Mac OSX for Go?

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

Configuring Sublime Text:

For Sublime Text, set the GOPATH in the User settings:

{
        "shell": ["/bin/bash"],
        "env": {"GOPATH": "/Users/#USERNAME#/go/"},
}
Copy after login

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!

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