Install homebrew: https://brew.sh/
Install Go:
brew install go
Edit 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 ~/.bashrc
Create 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.go
Add 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
Debug
icon in the sidebar. - Click on the cog icon in the
Debug
panel. Use the default values for the generatedlaunch.json
. - Add a breakpoint in your
hello.go
file - Click on the play icon to start debugging, and your breakpoint should be hit.