Skip to content
Skip to content
DocsGo LearningbeginnerGetting Started
Chapter 1 of 14·beginner·5 min read

Getting Started

Bắt Đầu

Install Go, set up modules, and write your first program

Hover or tap any paragraph to see Vietnamese translation

What is Go?

Go is a compiled, statically-typed programming language created by Google in 2009. It is designed to simplify systems programming, with a focus on speed, performance, and code readability. Go includes built-in garbage collection, easy-to-use concurrency via goroutines, and fast compilation times.

Go is used by major companies like Docker, Kubernetes, Cloudflare, and Uber. It is popular for backend services, command-line tools, and network applications. Unlike TypeScript (a dynamically-typed language that compiles to JavaScript), Go is a compiled language with a strong type system.

Installing Go

To install Go, download the official distribution from golang.org. The distribution includes the compiler (go), package management tools, and the standard library. After installation, verify it by checking the version.

Terminal
1# Download and install from https://golang.org/dl23# Verify installation (run in a new terminal)4go version56# Example output:7# go version go1.21.0 linux/amd64

Go uses the GOPATH environment variable to define the workspace directory (usually ~/go). However, from Go 1.11 onwards, module mode is the recommended approach — GOPATH is no longer required. Packages are managed via go.mod.

Your First Program

Create a new directory for your project. In Go, the simplest approach is to create a .go file with a main() function. No special setup tools are needed.

Terminal
1# Create a project directory2mkdir hello3cd hello45# Create your first Go file6cat > hello.go << 'EOF'7package main89import "fmt"1011func main() {12    fmt.Println("Hello, World!")13}14EOF

Explanation:

  • package main: All Go files must belong to a package. The main package is special — it contains the program entry point.
  • import "fmt": Imports the fmt (format) package from the standard library, allowing you to print output.
  • func main(): The main function is the entry point. It takes no parameters and returns nothing.
  • fmt.Println(): Prints a line of text to stdout with a trailing newline.

go run, go build, and go mod init

Go provides basic commands to run and build programs. go run compiles and runs directly. go build creates an executable binary.

Terminal
1# Run the program directly (compile and execute in one step)2go run hello.go34# Build an executable binary (creates 'hello' or 'hello.exe' on Windows)5go build67# Run the binary8./hello

To organize dependencies, create a Go module with go mod init. The module name usually follows the convention example.com/myapp.

Terminal
1# Initialize a module2go mod init example.com/hello34# This creates a go.mod file:5# module example.com/hello6# go 1.217# (no dependencies initially)

The go.mod File

The go.mod file defines your module and lists all external dependencies. It is similar to package.json in Node.js but simpler.

go.mod
1module example.com/hello23go 1.2145require (6    github.com/some/package v1.2.37)89require (10    github.com/another/package v0.1.0 // indirect11)
  • module: The module name — a unique identifier for your package.
  • go: The Go version this code is written for (not a hard requirement).
  • require: Lists external dependencies with specific versions.

IDE Setup

VS Code with the Go extension (golang.go) is the most popular development environment for Go. This extension provides code completion, type information, code navigation, debugging, and real-time diagnostics.

  • Install VS Code from https://code.visualstudio.com if you do not have it already.
  • Open Extensions (Ctrl+Shift+X), search for "Go" and install the official extension.
  • The extension will prompt you to install additional Go tools (gopls language server, dlv debugger). Accept the prompts to install them.
Tip
gopls (the Go Language Server) automatically downloads when you first open a Go project. This may take a few minutes depending on your internet connection speed.

Key Takeaways

Điểm Chính

  • Go is a compiled, statically-typed language created by GoogleGo là ngôn ngữ biên dịch, statically-typed được tạo bởi Google
  • go run compiles and runs your program directlygo run biên dịch và chạy chương trình trực tiếp
  • go mod init creates a module and go.mod file for dependency managementgo mod init tạo module và file go.mod để quản lý dependency
  • Every Go program needs package main with a main() entry point functionMỗi chương trình Go cần package main với hàm entry point main()

Practice

Test your understanding of this chapter

Quiz

What is the entry point function name in every Go program?

Tên hàm entry point trong mỗi chương trình Go là gì?

True or False

Go source files use the .go file extension.

File mã nguồn Go sử dụng phần mở rộng .go.

Code Challenge

Complete the command to run a Go program directly

Hoàn thành lệnh để chạy chương trình Go trực tiếp

go  hello.go
Quiz

Which command creates a go.mod file for dependency management?

Lệnh nào tạo file go.mod để quản lý dependency?

True or False

In Go, GOPATH is still required for modern module-based projects.

Trong Go, GOPATH vẫn bắt buộc cho các dự án dựa trên module hiện đại.

Built: 6/25/2026, 3:03:36 PM