Home > Backend Development > Golang > How to Set the $GOPATH Variable Permanently on Mac OSX?

How to Set the $GOPATH Variable Permanently on Mac OSX?

Susan Sarandon
Release: 2024-11-13 04:14:01
Original
396 people have browsed it

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 ' immediately after installation.

Manual Method for the Shell

For older versions of Go or for users who prefer manual configuration, the following steps should be followed:

  1. Edit the ~/.bash_profile file.
  2. Add the line: 'export GOPATH=$HOME/go'.
  3. Add the line: 'export PATH=$GOPATH/bin:$PATH'.

Ensure that the '$' symbol is included where indicated.

Configuration for Sublime Text

Users of Sublime Text can configure the $GOPATH variable as follows:

  1. Navigate to Sublime Text menu > Preferences > Package Settings > GoSublime > Settings: User.
  2. Add the following JSON code:
{
        "shell": ["/bin/bash"],
        "env": {"GOPATH": "/Users/#USERNAME#/go/"},
}
Copy after login

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!

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