Ver en Español
Getting started with Go
Apr 15, 2023
Updated: Jun 25, 2026

Getting started with Go

To start programming in Go, the first thing you need is the Go compiler installed. You can download the compiler from the official downloads page, available at https://go.dev/dl/.

Once you have downloaded the compiler, install it by following the instructions on the downloads page, which vary depending on your operating system.

Once the compiler is installed, you need a code editor or an integrated development environment (IDE). One option is JetBrains GoLand, available at https://www.jetbrains.com/go/. I, however, recommend Visual Studio Code. VS Code is a free, cross platform editor that offers many useful features for programming in Go, including: debugging support, syntax highlighting, code completion, refactoring, and Git integration.

You can download Visual Studio Code from https://code.visualstudio.com/Download.

The best Go extensions for Visual Studio Code

Once you have Visual Studio Code installed, I recommend installing the official Go extension:

  • Go for Visual Studio Code: this is the main extension, developed and maintained by the Go team at Google, the creator of the language. You can find it at https://marketplace.visualstudio.com/items?itemName=golang.go.

This extension is pretty much all you need. Under the hood it manages gopls, the official Go language server, which is what gives you code completion, "go to definition", refactoring, real time diagnostics, and much more. The first time you open a .go file, the extension will offer to install the tools it needs; accept and you will be ready to work.

Note: older guides often recommended third party packages such as "Go Extension Pack" or "Go Lang Tools". These are no longer needed today: the official golang.go extension with gopls replaces all of those tools and is the maintained, recommended choice.

Verifying your Go installation

To check that you can run Go on your computer, open a command line window or your terminal and run the following command:

go version

This will show you the version of the Go compiler installed on your computer. If you see the version, it means the compiler was installed correctly and you can already run Go.

If the command returns nothing, it means the compiler was not installed correctly. In that case, download and install Go again from https://go.dev/dl/ and, once installed, run the command again to confirm everything is in order.

The 10 most used Go commands

I invite you to explore each one in your terminal:

  • go run: compiles and runs a Go source file.
  • go build: compiles a package and its dependencies.
  • go get: adds and manages module dependencies in your go.mod file. Since Go 1.16 it is no longer used to install executable binaries.
  • go install: compiles and installs an executable binary. To install a tool, use go install pkg@version, for example go install golang.org/x/tools/gopls@latest.
  • go test: runs the unit tests for a package.
  • go fmt: formats your code according to Go's standard style. The common usage is go fmt./... to format the whole project. Under the hood it uses the gofmt tool.
  • go list: lists the packages imported by a program.
  • go doc: shows the documentation for a package or for an identifier within a package.
  • go vet: analyzes your source code looking for common mistakes and suspicious constructs.
  • go generate: runs the code generation commands declared in your source files.

Your first program: Hello, world

Before moving on to the exercises, let's look at what the simplest Go program looks like. Create a file called main.go with the following contents:

// package main defines the program's entry point
package main

// fmt is the standard package for formatted input and output
import "fmt"

// main is the function that runs when you start the program
func main() {
	fmt.Println("Hello, world!")
}

And to run it, simply execute:

go run main.go

If everything is fine, you will see Hello, world! printed in your terminal. You have just written and run your first Go program.

Conclusions

  • We learned how to install the Go compiler, the IDE, and the tools needed to get started.
  • We met the official golang.go extension for Visual Studio Code and gopls, the language server that makes it so powerful.
  • We explored the most used Go commands, which will help you get familiar with the language's basic tooling.
  • We wrote and ran our first "Hello, world" program.

Suggested exercises

  1. Install the Go compiler, Visual Studio Code, and the official golang.go extension.
  2. Create a basic Go project with go mod init project-name and open the folder in Visual Studio Code.
  3. Write a Go program that prints "Hello, world!" to the console and run it with go run.
  4. Add a function to your program that performs a basic math operation (addition, subtraction, multiplication, or division) and call it from the main function.
  5. Write unit tests for the function from the previous exercise and run them with go test.
  6. Use go fmt./... to format your code correctly and go vet to detect errors in your source code. Add comments and documentation following Go conventions and use go doc to view the generated documentation.
  7. Create a Git repository for your project and commit and push your changes throughout development.
  8. Experiment with other Go commands, such as go build, go install, and go list, to get more familiar with the language's tooling.
  9. Research other useful tools and configurations for Go development and try them out in your project.

3-point summary

  1. To get started with Go you need the compiler (from https://go.dev/dl/) and an editor like Visual Studio Code with the official golang.go extension.
  2. In modern Go, go get manages dependencies in your go.mod and go install pkg@version installs executable binaries.
  3. Verify your installation with go version, format with go fmt./..., check with go vet, and write your first program with go run.

That's all, I hope this post is useful to you and that you can apply it to a project you have in mind.

Leave me a comment if it helped, if you want to add an opinion, or if you have any questions. And remember, if you liked it, you can also share it using the social links below. Good luck on your Go adventure!

Sebastian Gomez

Sebastian Gomez

Creador de contenido principalmente acerca de tecnología.

Leave a Reply

0 Comments

Advertisements

Related Posts

Categorias