Install homebrew: https://brew.sh/
Install Go:
brew install goEdit your ~/.bashrc
vi ~/.bashrc
Add environment vars:
export GOPATH="${HOME}/go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
Reload your shell settings:
source ~/.bashrcCreate paths:
test -d "${GOPATH}" || mkdir "${GOPATH}"
test -d "${GOPATH}/bin" || mkdir "${GOPATH}/bin"
test -d "${GOPATH}/src/github.com" || mkdir -p "${GOPATH}/src/github.com"Create the src directory:
mkdir -p "${GOPATH}/src/github.com/yourusername/projectname"
cd "${GOPATH}/src/github.com/yourusername/projectname"Create a hello world file:
vi hello.goAdd the following:
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}Build and execute:
go build
./hello- Install the Go extension by Microsoft: https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go
- Click on the
Debugicon in the sidebar. - Click on the cog icon in the
Debugpanel. Use the default values for the generatedlaunch.json. - Add a breakpoint in your
hello.gofile - Click on the play icon to start debugging, and your breakpoint should be hit.