Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. Go Dictionary
  3. [Setup] Go Development Environment

[Setup] Go Development Environment

This page walks you through setting up a Go development environment. You can download an installer from the official website and start developing right away.

Installation

Windows: Install with the installer

Download the Windows installer from go.dev.

Featured downloads section on the Go official download page (installer list for each OS)

Nearly all Windows PCs have an x64 (amd64) CPU, so just download go1.26.2.windows-amd64.msi under Microsoft Windows. Only when running Windows on an Apple Silicon Mac (M1, M2, etc.) via Parallels or similar, pick windows-arm64.msi from the All downloads section at the bottom of the page.

Double-click the downloaded installer to run it.

Go installer

Click "Next" to agree to the license and proceed with the installation.

Click "Install" to start the installation.

Go installation in progress

When the following screen appears, the installation is complete. Click "Finish" to exit the installer.

Go installation complete

macOS: Install with Homebrew

On macOS, the common practice is to install Go from the command line using a package manager like Homebrew rather than a GUI installer. An official pkg installer is also provided, but this page shows the Homebrew approach.

Open a terminal and run the following command. Homebrew is a package manager for macOS — if it is not installed, follow the instructions at https://brew.sh/ to install it first.

brew install go

Verifying the installation

Run the following in any of Terminal, PowerShell, or Command Prompt.

go version
go version go1.22.3 darwin/arm64

If a version number is displayed, the installation was successful.

GOPATH and Module Mode

In older versions of Go, all source code had to be placed under a directory called GOPATH. Today, module mode is the standard, and you can create projects anywhere you like.

GOPATH is still used as the storage location for downloaded packages, but you rarely need to think about it during development.

Creating and Running a Project

1. Initialize a project

mkdir hello
cd hello
go mod init hello

First, create a directory for the project with mkdir and move into it. go mod init initializes a module (project) and creates a go.mod file inside the directory.

2. Create the source file

Use a text editor to create a file named main.go with the following content.

sample_main.go
package main

import "fmt"

func main() {
    fmt.Println("Kogami Shinya")
    fmt.Println("Tsunemori Akane")
}

3. Run

go run main.go
Kogami Shinya
Tsunemori Akane

If Kogami Shinya and Tsunemori Akane are displayed, you're all set.

Building (Compiling)

Use go build to generate an executable file.

go build -o hello
./hello
Kogami Shinya
Tsunemori Akane

Go also supports cross-compilation. You can generate an executable for a different OS by setting environment variables as shown below.

Example: generating a Windows executable on macOS/Linux:

GOOS=windows GOARCH=amd64 go build -o hello.exe

Commonly Used go Commands

CommandDescription
go run filename.goCompiles and runs in one step.
go buildGenerates an executable file.
go mod initInitializes a new module (project).
go mod tidyRemoves unused dependencies and adds missing ones.
go fmtFormats code to the Go standard style.
go testRuns tests.

If the Command Is Not Found

If your terminal displays go: command not found, the PATH may not be configured correctly. Follow the steps below to check and fix the issue.

1. Find the command location

Check where the command is located.

which go

If not found, check common installation locations.

ls /usr/local/go/bin/go
ls /opt/homebrew/bin/go

2. Check which shell you are using

echo $SHELL

If /bin/zsh is shown, edit ~/.zshrc; if /bin/bash is shown, edit ~/.bashrc.

3. Add to PATH

Once you know the command location, add the PATH to your shell configuration file.

For macOS (zsh):

echo 'export PATH="/usr/local/go/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For Linux (bash):

echo 'export PATH="/usr/local/go/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

About GOPATH and GOROOT

Go has two important environment variables. They are usually configured automatically, but check them if you encounter problems.

VariableDescriptionDefault
GOROOTThe Go installation directory./usr/local/go
GOPATHThe storage location for downloaded packages and executables installed with go install.~/go

Check the current settings.

go env GOROOT
go env GOPATH

To use commands installed with go install, also add GOPATH/bin to your PATH.

For macOS (zsh):

echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For Linux (bash):

echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

For Windows, go to "Advanced System Settings" → "Environment Variables" → "Path" to add the entry. The official installer sets this automatically. If it does not, add C:\Program Files\Go\bin to Path manually.

Uninstalling Go

To uninstall the Go version installed via Homebrew, run the following command.

brew uninstall go

On Windows, go to Settings → Apps → Installed apps, find "Go Programming Language", and click Uninstall.

Choosing an Editor

ToolDescription
Visual Studio Code (commonly known as VSCode)Currently the most popular editor for Go. The official Go extension provides code completion, formatting, debugging, and linting. Available on Windows, macOS, and Linux.
Sublime TextA lightweight, extremely fast editor. Its simple interface lets you focus on coding. Available on Windows, macOS, and Linux.
Hidemaru EditorA legendary Japanese text editor first released in 1993. Lightweight, fast, and equipped with a powerful macro system. Windows only, one-time purchase.
GoLandA Go-dedicated IDE (Integrated Development Environment — a tool combining code editing, execution, and debugging) by JetBrains. Offers advanced code analysis, refactoring, and integrated debugging. Paid.
VimA classic terminal-based editor popular among Go developers. With the vim-go plugin, it provides a powerful Go development experience.

These days, Visual Studio Code seems to be the most widely used editor, but the webmaster personally loves simple and lightweight editors, so he currently uses Sublime Text. Feel free to use this as a reference.

A note about Hidemaru Editor: first released in 1993, Hidemaru is lightweight, features powerful search and replace with regular expressions, and can be customized with macros. In modern terms, macros are similar to add-ons — and Hidemaru had this capability back in the 1990s, a remarkably forward-thinking design that makes it a truly wonderful editor.

The webmaster himself used Hidemaru Editor for programming from the Windows 3.1 era through Windows 7, and owes a great deal to it over the years. Its developer, Hideo Saito, continues to update Hidemaru to this day — it runs perfectly on Windows 11 and other 64-bit versions of Windows. You can purchase Hidemaru Editor from here — it is a one-time purchase for around 4,000 yen (about $27), and having it on a Windows machine can be surprisingly handy.

(´-`).。oO(The webmaster wanted to give a personal shout-out to Mr. Saito, who he has relied on for years...)

(´-`).。oO(And yet, after 30+ years of use, the total cost has been just around $27... it's hard to find anything with better value for money...)

If you find any errors or copyright issues, please .