Go Getting Started Guide
Getting started with Go (Golang) is simple and developer-friendly. In this guide, you’ll learn how to install Go, set up your development environment, and run your first Go program step by step.
What You Need to Start with Go
To begin programming in Go, you need two essential tools:
1. Code Editor or IDE
A code editor helps you write and manage your Go code efficiently. Popular choices include:
- Visual Studio Code (VS Code) – Beginner-friendly and widely used
- Vim – Lightweight and powerful for advanced users
- Eclipse – Full-featured IDE
- Notepad++ – Simple text editor
2. Go Compiler (Go Toolchain)
Unlike traditional languages that use external compilers like GCC, Go comes with its own built-in compiler and toolchain. This includes commands for building, running, and managing projects.
Installing Go
Follow these steps to install Go on your system:
- Visit the official Go downloads page: https://golang.org/dl/
- Download the installer for your operating system (Windows, macOS, or Linux)
- Run the installer and follow the setup instructions
- Verify the installation by opening a terminal or command prompt and running:
If you see the version displayed, Go has been installed successfully.
Setting Up VS Code for Go Development
We recommend using Visual Studio Code for a smooth development experience.
Steps to Configure VS Code
- Download and install VS Code from: https://code.visualstudio.com/
- Open VS Code
- Go to Extensions (or press Ctrl + Shift + X)
- Search for "Go"
- Install the official Go extension published by Google
- Open the Command Palette (Ctrl + Shift + P)
-
Run:
Go: Install/Update Tools - Select all tools and click OK
Your environment is now fully configured for Go development.
Go Project Initialization
Before writing code, initialize a Go module. This helps manage dependencies and organize your project.
Open a terminal and run:
This command creates a go.mod file, which defines your project
module.
Your First Go Program
Now, let’s write and run your first Go program.
Step 1: Create a New File
Create a file named: main.go
Step 2: Add the Following Code
Building an Executable
To compile your Go program into an executable file, use:
This generates a binary file:
- On Windows →
main.exe - On macOS/Linux →
main
You can run it directly without needing the Go toolchain.
Bonus Example: Simple Calculator in Go
Here’s a slightly more practical example:
Tips for Beginners
-
Always use
go mod initwhen starting a new project. - Keep your code inside a single folder (workspace).
-
Use
go runfor testing andgo buildfor deployment. - Explore the official Go documentation and standard library regularly.
You’ve now:
- Installed Go
- Configured your development environment
- Written and executed your first program
- Built a standalone executable
