Go Brew Fish
Setting up Go on MacOS with Brew using Fish shell. This guide expects that you are already using fish shell on Mac and are comfortable using the command line. This guide does not cover setting up Brew either.
Install Go via Brew
brew install go
Configure Go environment.
Add the following to your ~/.config/fish/config.fish
file.
GOPATH is where you will have your Go code. I have chosen to use my Development
directory in the home directory. Later we will make a new Go
directory.
GOROOT is where go
was installed by brew.
set -x GOPATH ~/Development/Go
set -x GOROOT (brew --prefix golang)/libexecset -x PATH $PATH $GOROOT/bin $GOPATH/bin
Create a new directory for our Go code.
mkdir -p ~/Development/Go/src
Source the config file or open a new terminal window.
source ~/.config/fish/config.fish
Testing
Now create a hello
directory for testing and change to that directory.
mkdir -p $GOPATH/src/hellocd $GOPATH/src/hello
Create and edit hello.go
in the newly created directory with the sample code below.
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
From within the hello directory, run the following
go run hello.go
If everything worked, you should see “hello, world” returned.