Home > Backend Development > Golang > How to Set GOPATH on Mac OSX?

How to Set GOPATH on Mac OSX?

Patricia Arquette
Release: 2024-11-23 14:01:11
Original
807 people have browsed it

How to Set GOPATH on Mac OSX?

Setting $GOPATH on Mac OSX

Problem Statement:
When attempting to run Go example code, an error is encountered indicating that the GOPATH environment variable is unset.

Solution:

For the Shell:

  1. Ensure that your ~/.bash_profile file includes the following lines:

    export GOPATH=$HOME/go
    export PATH=$GOPATH/bin:$PATH
    Copy after login

    Note: Use "$" symbols only at the appropriate places as shown.

For Sublime Text:

  1. Navigate to: Sublime Text menu > Preferences > Package Settings > GoSublime > Settings: User
  2. Add the following JSON to the file:

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

    Replace "#USERNAME#" with your actual username.

  3. Ensure that your GOPATH is set to the root of your Go folder (where src, pkg, and bin reside), not the full path to a specific package.

Important Note:

As of Go 1.8 (released Feb 2017), the GOPATH is automatically determined by the Go toolchain. It defaults to $HOME/go on Mac OSX. This simplifies the setup process and allows you to start using Go immediately.

The above is the detailed content of How to Set GOPATH 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