DEV Community

Ko Takagi
Ko Takagi

Posted on

53 9

How to setup Golang with VSCode

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!👍

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (13)

Collapse
 
jjamieson1 profile image
Jamie Jamieson

Thank you! Easy start for me

Collapse
 
ko31 profile image
Ko Takagi

You're welcome!

Collapse
 
pedromassango profile image
Pedro Massango

Thanks for saving me today. I already spent 3h on this

Collapse
 
n1ru4l profile image
Laurin Quast

Exactly what I needed 🚀

Collapse
 
ko31 profile image
Ko Takagi

Thanks! 😊

Collapse
 
spiropoulos94 profile image
NikosSp

all good, but I have no curly lines error highlighting. anyway to fix this?

Collapse
 
koss_kokos profile image
Mike

Thanks bro, I`m got tangled up in folders and couldn't start studying

Collapse
 
mngt profile image
Aman Gautam

Great Articles!

Collapse
 
velbie profile image
velbie

Thank you Takagi!

Collapse
 
ko31 profile image
Ko Takagi

Thanks! 👍

Collapse
 
xleki profile image
xleki

How do I have the little play button in the top right like in python

Collapse
 
daveton profile image
Omokefe Ovie David

Thanks, this helps

Collapse
 
jhoval profile image
Mauro Franchini

Thanks! Fast and straight forward.

Neon image

Set up a Neon project in seconds and connect from a Go application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay