October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Getting Started with Go: How to Use `go run` and `go build`

Use `go run .` for a quick development run, `go build` to create an executable, and `go install` to make a command available by name in your shell.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use go run . to compile and run a Go program while you develop it; use go build when you want a separate executable file. If you want to install a command so you can run it by name from elsewhere, use go install.

What you need to run a Go program

The official Go getting-started tutorial expects some programming experience, an editor, and a terminal. Start by installing Go using the instructions linked from that tutorial. You will also need a Go module containing your program.

As an Amazon Associate I earn from qualifying purchases.

Go organizes code into packages, and packages into modules. A program intended to run as a command uses package main. The official Go code guide explains this organization and the executable-package requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run your program during development

Open a terminal in the module directory and run:

go run .

The dot tells the Go command to use the package in the current directory. Go compiles and runs the program, which makes this a convenient way to try changes without first creating a separate executable file. The official compile-and-install tutorial describes go run as a shortcut for frequent development runs; it does not generate a binary executable.

Build an executable file

When you want a file you can run separately, open a terminal in the application directory and use:

go build

The Go command compiles the packages and their dependencies. It does not install the result. In the tutorial’s example, the built program can be run from the application directory as ./hello on Linux or macOS, or hello.exe on Windows. The output name and invocation depend on the command and operating system, so follow the name produced for your project.

Choose the command for your goal

Command Use it when Result
go run . You want to compile and run the current package during development. Runs the program without generating a binary executable.
go build You want an executable file to run separately. Builds the program and its dependencies but does not install them.
go install You want to install a command so it can be invoked by name from your shell. Installs the command in the Go install location; the location and shell-path setup vary by platform and environment.

These commands are part of Go’s package-oriented toolchain, not a general-purpose build system. Go’s documentation about the go command describes how it automates downloading, building, installing, and testing Go packages and commands.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Install a command for use by name

Building a file and installing a command are separate tasks. If you want to invoke your command without staying in its application directory, use go install. The Go tutorial provides platform-specific examples and explains how to find or configure the install location. Make sure that location is included in your shell’s PATH; otherwise, the shell may not find the command by name.

A practical first-run sequence

  1. Install Go using the official getting-started instructions.
  2. Create or open a module, then write your executable program in a package main.
  3. From the module directory, run go run . to compile and launch the program.
  4. When you need a separate executable, run go build from the application directory and launch the resulting file.
  5. Use go install instead if your goal is to run the command by name from other directories, and ensure the install location is on your shell path.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.