Setting Up Go Development Environment
Start with Setting Up Go Development Environment
A useful Go development environment is a code editor plus the Go toolchain. VS Code with the official Go extension provides editor assistance while the terminal remains the source of truth for compiling and running programs.
What you’ll learn
- Set up an editor for Go.
- Create a local module directory.
- Use the integrated terminal to run and format Go code.
Understand the idea
Install Visual Studio Code, open Extensions and install the Go extension maintained by the Go team. Open a project folder rather than editing random files in unrelated locations.
In the integrated terminal, create a directory, initialize a module and open main.go. The editor can help with completion, imports and formatting, but a missing extension must not stop you from using go run . in the terminal.
Tools, syntax and practical notes
Project setup
mkdir go-practice
cd go-practice
go mod init example.com/go-practice
go run .
go fmt ./...Run go run . after saving main.go. The module path above is illustrative and suitable for local learning.
Run a complete Go example
This example is a complete program. Save it as main.go or paste it into the Go Playground.
Go code
package main
import "fmt"
func main() {
city := "Hyderabad"
fmt.Println("Learning from", city)
}
Output
Learning from HyderabadTrace what the program does
Save the source file. The Go extension can offer completion for fmt.Println, and formatting will align the code according to Go conventions. The terminal compiles the code from the current directory when you run the module.
Avoid common mistakes
- Opening the wrong folder often makes
go run .appear to fail for unrelated reasons. - Editor syntax highlighting does not prove the program compiles; always run or test the code.
Try it yourself
Create a folder named go-practice, initialize a module and execute the example from the integrated terminal.
Tip: Edit the example above, predict the output, and run the modified code to test your reasoning.
Check your understanding
What you should remember
You have practiced Setting Up Go Development Environment in a small, self-contained program. The important habit is to predict what runs, inspect the actual output and distinguish the language rule from the particular example.
Before continuing, make sure you can explain the program to someone who has not seen it, including the line that changes its result.
Reaching the recap and completing the quizzes are separate milestones.