Setting up Debugging in Go with VS Code
Tags: go, beginners, productivity
Published: 2020-08-17 14:05:23

---
title: Setting up Debugging in Go with VS Code
published: true
description: How to use Delve and VS Code to debug your go scripts
tags: [go,beginners,productivity]
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/wrdk943kwg0jdcvx4ez6.png
---

Go has some really great tools, and most of these are all built-in so you don't have to look very far to do much outside the core language and tooling. Documentation is comprehensive, the language is minimalist in nature, and it is surrounded by a massive community. In this article, I'll show you some companion projects that help you with debugging your go projects.

## Delve

There are a few projects you can use to debug your go applications. The one most recommend is [Delve](https://github.com/derekparker/delve) as an alternative to the [gdb](https://golang.org/doc/gdb). GDB is the GNU symbolic debugger and prior to delve this was the only way to actually debug Go programs. Luckily, that's not the case anymore and you can now combine Delve with VS Code quite easily.

### [Installing Delve in Linux](https://github.com/derekparker/delve/blob/master/Documentation/installation/linux/install.md)

You can use the standard `go get` method

```
go get github.com/go-delve/delve/cmd/dlv
```

Alternatively, you can clone the repo directly and install with make.

```
$ git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve
$ cd $GOPATH/src/github.com/go-delve/delve
$ make install
```

### [Installing Delve in mac OS](https://github.com/derekparker/delve/blob/master/Documentation/installation/osx/install.md)

You will need to make sure you have `xcode-select` command line tools installed prior to this (as well as [Go](https://golang.org/) itself). 

```
xcode-select --install
```

Once you have that, use the standard `go get` to install.

```
go get github.com/go-delve/delve/cmd/dlv
```


### [Installing Delve in Windows](https://github.com/derekparker/delve/blob/master/Documentation/installation/windows/install.md)

Delve can be installed in Windows with the `go get` method

```
go get github.com/go-delve/delve/cmd/dlv
```

## Setting up VS Code

You can setup Go in VS Code by making sure you have the [vscode-go](https://github.com/golang/vscode-go) extension installed. You can do this by:

* Make sure you have Go installed and it is located by VS Code. Open up the command palette (Ctrl+Shift+P / Cmd+Shift+P) and run `Go: Locate Configured Go Tools`. 
* Navigate to the extensions (Ctrl+Shift+X / Cmd+Shift+X) and search for "Go". (publisher is `golang.Go`).

The VS Code extension supports Intellisense, code navigation, debugging, testing, and shows build, lint, vet diagnostics in detail. 

Next you'll need to install the `dlv` tool for vs code itself.

* Open up Command Palette now (Ctrl+Shift+P / Cmd+Shift+P) and select `Go: Install/Update Tools` then search/select `dlv`. 

Once you have this, you are ready to start debugging!

Open up the package main or test file you want to debug. Open up the command palette (Ctrl+Shift+P / Cmd+Shift+P) and select `Debug: Start Debugging` then select `Go`. This will start things up and hit your breakpoints as you would expect.

![Debugging in VS Code](https://dev-to-uploads.s3.amazonaws.com/i/8opinfzncgbnrd8ycp9n.png)

For more details, check out the [extension for VS Code](https://github.com/golang/vscode-go) and the various [integrations for Delve](https://github.com/derekparker/delve/blob/master/Documentation/EditorIntegration.md)

Best of luck!