DEV Community

loading...

How to setup Golang with VSCode

ko31 profile image Ko Takagi ・2 min read

I have used Golang some years ago, but unfortunately I hadn't tried to do it in a long time and had forgotten all about it....

So I set it up from the beginning with a fresh mind.😊

The environment I used is as follows.

  • macOS Catalina 10.15.5
  • Visual Studio Code 1.46.1

Installing Go

Download and install Go from the following link.

Go

After the installation, open a terminal and check the version using the following command.

$ go version
go version go1.15.2 darwin/amd64
Enter fullscreen mode Exit fullscreen mode

Create directory for GOPATH setting.

$ mkdir ~/go
Enter fullscreen mode Exit fullscreen mode

For GOPATH envirionment variable, add the following lines to the ~/.bash_profile.

export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$PATH 
Enter fullscreen mode Exit fullscreen mode

Installing Visual Studio Code

Download and install VSCode from the following link.

After the installation, Launch VSCode.

Open the Extensions Marketplace (Cmd+Shift+X), search Go and install it.

Go extension

open the Command Palette (Cmd+Shift+P) and run the Go: Install/Update Tools command.

Go extensions

Install all the Go extensions listed there.

Go extensions

Start coding

Create hello.go in VSCode.

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
Enter fullscreen mode Exit fullscreen mode

By default, auto-completion and formatting for code saving are enabled. That's great.

auto-completion

Open a terminal (Ctrl+`) and execute the following command.

$ go run hello.go 
Hello, world!
Enter fullscreen mode Exit fullscreen mode

Have fun!πŸ‘

Discussion (6)

pic
Editor guide
Collapse
jjamieson1 profile image
Jamie Jamieson

Thank you! Easy start for me

Collapse
ko31 profile image
Ko Takagi Author

You're welcome!

Collapse
n1ru4l profile image
Laurin Quast

Exactly what I needed πŸš€

Collapse
ko31 profile image
Ko Takagi Author

Thanks! 😊

Collapse
velbie profile image
velbie

Thank you Takagi!

Collapse
ko31 profile image
Ko Takagi Author

Thanks! πŸ‘