{"id":704,"date":"2026-10-03T13:00:00","date_gmt":"2026-10-03T07:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/"},"modified":"2026-11-29T01:29:45","modified_gmt":"2026-11-28T19:59:45","slug":"how-to-run-a-go-program","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/","title":{"rendered":"How to Run a Go Program: go run, go build and go install"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To run a Go program, you use one of three commands: <code>go run<\/code>, <code>go build<\/code> or <code>go install<\/code>. Each one compiles your code, but each gives you a different result. In this post, you will learn all three, plus how to pass arguments, read input, use exit codes and fix the errors beginners see most.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the second post in our Go programs series. If Go is not on your computer yet, start with the <a href=\"https:\/\/smitabharat.com\/blog\/go-installation-windows-macos-linux\/\">Go installation guide for Windows, macOS and Linux<\/a>. At the end, you will find interview questions with small programs and their real output.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Does It Mean to Run a Go Program?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Go is a compiled language. So, before your code can run, the compiler turns your <code>.go<\/code> files into a machine code file called a binary. Then your computer runs that binary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simple way to picture it. Your source code is a recipe written in English. The compiler is a cook who turns the recipe into a finished dish. Running the program is serving that dish, and you can serve it again without cooking it twice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Parts of Every Go Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you run a Go program, let&#8217;s look at a tiny one. Every runnable Go program needs the same three parts.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main \/\/ this file is a program, not a library\n\nimport \"fmt\" \/\/ fmt is the standard package for printing\n\n\/\/ main is the first function Go runs\nfunc main() {\n    fmt.Println(\"Hello from Go!\") \/\/ Println prints the text and a new line\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello from Go!<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>package main<\/code> tells Go this code is a program, not a library.<\/li>\n\n\n<li><code>import \"fmt\"<\/code> loads the standard package for printing.<\/li>\n\n\n<li><code>func main()<\/code> is the entry point. The program starts here and stops when it returns.<\/li>\n\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Easy Example: Code Runs from Top to Bottom<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you run a Go program, the lines inside <code>main<\/code> run one by one, from top to bottom. This small program makes that order easy to see.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main prints three steps in order\nfunc main() {\n    \/\/ := creates a new variable and gives it a value\n    name := \"Asha\"\n\n    fmt.Println(\"Step 1: the program starts\")\n    fmt.Println(\"Step 2: hello,\", name)\n    fmt.Println(\"Step 3: the program ends\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Step 1: the program starts\nStep 2: hello, Asha\nStep 3: the program ends<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, Go stores &#8220;Asha&#8221; in the variable <code>name<\/code>. Then it runs each <code>Println<\/code> line in the order you wrote them. When <code>main<\/code> reaches its last line, the program stops.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set Up a Folder to Run a Go Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Modern Go uses modules. A module is a folder with a <code>go.mod<\/code> file that names your project. You create it once per project with <code>go mod init<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir hello\ncd hello\ngo mod init example.com\/hello<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After you add <code>main.go<\/code>, the folder looks like this. The <code>go.mod<\/code> file is small and Go writes it for you.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hello\/\n    go.mod\n    main.go<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will learn more about modules in our <a href=\"https:\/\/smitabharat.com\/blog\/go-modules-packages-explained\/\">Go modules and packages guide<\/a>. For now, just remember that every project starts with <code>go mod init<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Three Ways to Run a Go Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">All three commands compile your code. The difference is where the binary ends up, and whether Go runs it for you.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-1024x640.png\" alt=\"Run a Go program diagram showing go run, go build and go install flows\" class=\"wp-image-695\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">go run builds into a temporary folder and runs the program, go build saves a binary in your folder, and go install saves it in GOBIN.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1: Run a Go Program with go run<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>go run<\/code> compiles the code into a temporary folder, runs it, and then cleans up. It is the fastest way to run a Go program while you are learning. You can pass one file or the whole package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go run main.go\ngo run .<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello from Go!\nHello from Go!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>go run .<\/code> as your habit. The dot means &#8220;the package in this folder&#8221;, so Go includes every <code>.go<\/code> file in it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method 2: Build First, Then Run a Go Program<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>go build<\/code> compiles the code and saves the binary in the current folder. The file is named after your module, so here it is <code>hello<\/code> on Linux and macOS, or <code>hello.exe<\/code> on Windows. Then you run the file yourself.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go build\n.\/hello<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello from Go!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On Windows, run <code>.\\hello.exe<\/code> instead. You can also choose the file name with the <code>-o<\/code> flag, for example <code>go build -o bin\/app .<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method 3: Install and Run a Go Program Anywhere<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>go install<\/code> builds the binary and moves it to your GOBIN folder, which is usually <code>$HOME\/go\/bin<\/code>. If that folder is on your PATH, you can run the program from any folder by name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go install\nhello<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello from Go!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is how Go developers install command line tools. For example, <code>go install golang.org\/x\/tools\/cmd\/goimports@latest<\/code> installs a popular formatter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">go run vs go build vs go install<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the three ways to run a Go program side by side.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>go run<\/th><th>go build<\/th><th>go install<\/th><\/tr><\/thead><tbody><tr><td>Compiles code<\/td><td>Yes<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Runs the program<\/td><td>Yes, right away<\/td><td>No<\/td><td>No<\/td><\/tr><tr><td>Keeps a binary<\/td><td>No, temporary only<\/td><td>Yes, in current folder<\/td><td>Yes, in GOBIN<\/td><\/tr><tr><td>Best for<\/td><td>Learning and quick tests<\/td><td>Shipping or testing a binary<\/td><td>Installing tools<\/td><\/tr><tr><td>Speed on reruns<\/td><td>Uses the build cache<\/td><td>Uses the build cache<\/td><td>Uses the build cache<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-1024x640.png\" alt=\"Run a Go program comparison of go run, go build and go install\" class=\"wp-image-696\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Pick go run while coding, go build to ship a file, and go install to use a tool everywhere.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, use <code>go run<\/code> while you code, <code>go build<\/code> when you need a file to ship, and <code>go install<\/code> when you want a command on your PATH.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Run a Go Program with Many Files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Real programs have more than one file. Let&#8217;s split our greeting into a second file, <code>greet.go<\/code>, in the same folder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ greet.go\npackage main\n\n\/\/ greet builds a friendly message for the given name\nfunc greet(name string) string {\n    return \"Hello, \" + name + \"!\" \/\/ + joins strings together\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ main.go\npackage main\n\nimport \"fmt\"\n\n\/\/ main calls greet, which lives in the other file\nfunc main() {\n    fmt.Println(greet(\"Asha\"))\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now watch what happens with each command. The first one fails, and the second one works.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ go run main.go\n# command-line-arguments\n.\/main.go:8:17: undefined: greet\n\n$ go run .\nHello, Asha!<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The reason is simple. <code>go run main.go<\/code> only compiles the one file you named, so Go never sees <code>greet.go<\/code>. On the other hand, <code>go run .<\/code> compiles the whole package, so both files are included.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pass Arguments When You Run a Go Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Many programs need input from the command line. Go stores these values in <code>os.Args<\/code>. The first item is always the program path, and your arguments come after it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Easy Example: Greet a Name from the Command Line<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s start with one word. This program reads a name after the program name and greets it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\" \/\/ os gives access to the command line words\n)\n\n\/\/ main greets the name typed after the program name\nfunc main() {\n    \/\/ len(os.Args) counts the items; item 0 is the program path\n    if len(os.Args) &lt; 2 {\n        fmt.Println(\"Please type a name after the program name.\")\n        return \/\/ stop main early\n    }\n\n    name := os.Args[1] \/\/ the first word you typed\n    fmt.Println(\"Hello,\", name)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run it with one word after the dot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go run . Asha<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Hello, Asha<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, the program checks that you typed at least one word. If you did not, it prints a hint and stops. Otherwise, it reads <code>os.Args[1]<\/code> and prints the greeting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Run a Go Program with Many Arguments<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s print every word you pass, with its position.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main prints how many items os.Args holds, then each argument\nfunc main() {\n    fmt.Println(\"Total items:\", len(os.Args))\n\n    \/\/ os.Args[1:] skips item 0, the program path\n    \/\/ range gives the position (i) and the value (arg) of each item\n    for i, arg := range os.Args[1:] {\n        fmt.Printf(\"Arg %d: %s\\n\", i+1, arg) \/\/ %d prints a number, %s prints text\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>go run . apple banana<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Total items: 3\nArg 1: apple\nArg 2: banana<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So the program sees three items, the path plus two words. The loop starts at the first real argument, and <code>i+1<\/code> makes the count start at 1 instead of 0. For named options like <code>-port=8080<\/code>, use the flag package from our <a href=\"https:\/\/smitabharat.com\/blog\/go-flag-package-cli\/\">Go command line tools guide<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read Input and Return Exit Codes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Programs often read from the keyboard and tell the system if they worked. This example reads a name and exits with code 1 when the name is empty.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"bufio\"   \/\/ bufio reads input in bigger pieces, such as a full line\n    \"fmt\"\n    \"os\"\n    \"strings\" \/\/ strings has helpers for text\n)\n\n\/\/ main reads a name and exits with code 1 if it is empty\nfunc main() {\n    fmt.Print(\"Your name: \") \/\/ Print does not add a new line\n\n    \/\/ Step 1: read one full line from the keyboard (os.Stdin)\n    reader := bufio.NewReader(os.Stdin)\n    line, _ := reader.ReadString('\\n') \/\/ _ ignores the second value (the error)\n\n    \/\/ Step 2: remove spaces and the new line at the end\n    name := strings.TrimSpace(line)\n\n    \/\/ Step 3: stop with a failure code when the name is empty\n    if name == \"\" {\n        fmt.Println(\"No name given\")\n        os.Exit(1) \/\/ a non-zero code means failure\n    }\n    fmt.Println(\"Welcome,\", name)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We type &#8220;Ravi&#8221; and press Enter. You can also pipe it in with <code>echo \"Ravi\" | go run .<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ravi<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Your name: Welcome, Ravi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When the input is empty, the program stops with code 1.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ echo \"\" | go run .\nYour name: No name given\nexit status 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>bufio.NewReader<\/code> reads a full line, and <code>strings.TrimSpace<\/code> removes the new line at the end. Also, the line &#8220;exit status 1&#8221; comes from <code>go run<\/code> itself. When you run a built binary, you only see the code with <code>echo $?<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Format and Check Code Before You Run It<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Two more commands help you write clean code. <code>go fmt<\/code> fixes spacing and layout, and <code>go vet<\/code> finds bugs the compiler misses. Let&#8217;s give <code>go vet<\/code> something to catch.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ main has a bug: %d expects a number, but we pass text\nfunc main() {\n    fmt.Printf(\"Count: %d\\n\", \"ten\") \/\/ wrong type for %d\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ go vet .\n# example.com\/hello\n# [example.com\/hello]\n.\/main.go:7:5: fmt.Printf format %d has arg \"ten\" of wrong type string<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The code compiles, but it would print a wrong result. So run <code>go fmt .\/...<\/code> and <code>go vet .\/...<\/code> before every commit. Most editors run them on save for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Errors When You Run a Go Program<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you run a Go program for the first time, you may hit an error. The table below lists the errors beginners see most, with the fix for each one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error message<\/th><th>Why it happens<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>go.mod file not found<\/td><td>No module in this folder<\/td><td>Run go mod init<\/td><\/tr><tr><td>undefined: greet<\/td><td>You ran one file only<\/td><td>Use go run .<\/td><\/tr><tr><td>is not a main package<\/td><td>Package is not main<\/td><td>Change to package main<\/td><\/tr><tr><td>declared and not used<\/td><td>Unused local variable<\/td><td>Use it or delete it<\/td><\/tr><tr><td>&#8220;os&#8221; imported and not used<\/td><td>Unused import<\/td><td>Remove the import<\/td><\/tr><tr><td>missing function body \/ no main<\/td><td>main is missing<\/td><td>Add func main()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Running one file in a big package:<\/strong> use <code>go run .<\/code> so every file is included.<\/li>\n\n\n<li><strong>Forgetting the module:<\/strong> without <code>go.mod<\/code>, newer Go versions refuse to build. Run <code>go mod init<\/code> first.<\/li>\n\n\n<li><strong>Committing binaries:<\/strong> add your built files, such as <code>hello<\/code> or <code>hello.exe<\/code>, to <code>.gitignore<\/code>.<\/li>\n\n\n<li><strong>Expecting defer to run after os.Exit:<\/strong> <code>os.Exit<\/code> stops at once, so deferred calls are skipped.<\/li>\n\n\n<li><strong>Missing GOBIN on PATH:<\/strong> after <code>go install<\/code>, the command is &#8220;not found&#8221; until <code>$HOME\/go\/bin<\/code> is on PATH.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use go run . while learning<\/strong>, because it always includes the whole package.<\/li>\n\n\n<li><strong>Use go build -o<\/strong> to give binaries clear names, such as <code>bin\/api<\/code>.<\/li>\n\n\n<li><strong>Keep one main package per program.<\/strong> For many programs in one repo, use <code>cmd\/&lt;name&gt;\/main.go<\/code> folders.<\/li>\n\n\n<li><strong>Run go vet and tests before you ship<\/strong>, since they catch bugs the compiler accepts.<\/li>\n\n\n<li><strong>Return a non-zero exit code on failure<\/strong>, so scripts and CI tools can detect errors.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Run a Go Program: Interview Questions and Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These are the run and build questions interviewers ask most. Many include a short program, so you can run a Go program yourself and compare the output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Questions on How to Run a Go Program<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What happens when you type go run main.go?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go compiles the file into a temporary folder, runs the binary, and then deletes it. The build cache keeps compiled packages, so the second run is faster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What is the difference between go build and go install?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both compile the code. <code>go build<\/code> leaves the binary in the current folder, while <code>go install<\/code> moves it to GOBIN or <code>$GOPATH\/bin<\/code>. Use install for tools you want on your PATH.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. Why does go run main.go fail with &#8220;undefined&#8221; when go run . works?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>go run main.go<\/code> only compiles the file you named. If a function lives in another file of the same package, Go cannot see it. <code>go run .<\/code> compiles all files in the package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. Can you run a Go program without a main function?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. A runnable program needs <code>package main<\/code> with <code>func main()<\/code>. Without main, the build fails, and Go reports that the function main is undeclared.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. Where does go build put the binary, and what is its name?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It puts it in the current folder. The name comes from the last part of the module path or folder name, such as <code>hello<\/code>. On Windows, Go adds <code>.exe<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. How do you build a binary with a custom name?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>-o<\/code> flag, for example <code>go build -o bin\/server .<\/code>. Go creates the <code>bin<\/code> folder if needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Program Output Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What does this program print?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main shows that os.Exit skips deferred calls\nfunc main() {\n    defer fmt.Println(\"bye\") \/\/ defer means \"run this when main returns\"\n    fmt.Println(\"start\")\n    os.Exit(0) \/\/ stop the program now, so main never returns\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>start<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It prints only &#8220;start&#8221;. <code>os.Exit<\/code> ends the program right away, so the deferred <code>Println<\/code> never runs. That is why you should return from main instead of calling <code>os.Exit<\/code> when you need cleanup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. In what order do init and main run?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport \"fmt\"\n\n\/\/ message is a package variable, so Go sets it before init and main\nvar message = makeMessage()\n\n\/\/ makeMessage prints a line and returns the value for message\nfunc makeMessage() string {\n    fmt.Println(\"1. package variable\")\n    return \"ready\"\n}\n\n\/\/ init runs by itself after package variables and before main\nfunc init() {\n    fmt.Println(\"2. init\")\n}\n\n\/\/ main runs last\nfunc main() {\n    fmt.Println(\"3. main:\", message)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1. package variable\n2. init\n3. main: ready<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go first sets package variables, then runs every <code>init<\/code> function, and finally calls <code>main<\/code>. A file can even have more than one <code>init<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What is os.Args[0]?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is the path of the running program. With <code>go run<\/code>, it points to a binary in a temporary folder. Your own arguments start at <code>os.Args[1]<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What does this program print with go run . one two?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\n\/\/ main prints the number of items and the last item in os.Args\nfunc main() {\n    count := len(os.Args)     \/\/ program path + one + two = 3\n    last := os.Args[count-1] \/\/ positions start at 0, so the last one is count-1\n    fmt.Println(count, last)\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3 two<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There are three items: the program path, &#8220;one&#8221; and &#8220;two&#8221;. The last item is &#8220;two&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. Why does this program fail to compile?<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n    \"fmt\"\n    \"os\"\n)\n\nfunc main() {\n    count := 5\n    fmt.Println(\"hi\")\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/main.go:5:5: \"os\" imported and not used\n.\/main.go:9:5: declared and not used: count<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Go does not allow unused imports or unused local variables. This rule keeps code clean, and the fix is to use them or delete them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Build and Tool Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What do go fmt and go vet do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>go fmt<\/code> rewrites code into the standard Go style. <code>go vet<\/code> looks for likely bugs, such as a wrong Printf verb or unreachable code. Neither one changes how correct code behaves.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. How do you make a smaller binary?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build with <code>go build -ldflags=\"-s -w\"<\/code>. These flags remove the symbol table and debug info, so the file gets smaller. The program still works the same way.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. Why is a Go binary larger than a C hello world?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go builds static binaries by default. The file includes the runtime, the garbage collector and every package you use. So it runs without any extra installs on the target machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. How do you build a Windows .exe on Linux?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set the target system before the build, for example <code>GOOS=windows GOARCH=amd64 go build -o app.exe .<\/code>. Go supports this cross compiling out of the box.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Build Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. How do you run a program with the race detector?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the <code>-race<\/code> flag, as in <code>go run -race .<\/code>. Go then reports when two goroutines touch the same memory without a lock. It is slower, so use it in testing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. What does go build .\/&#8230; mean?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.\/...<\/code> pattern means &#8220;this folder and every folder below it&#8221;. So <code>go build .\/...<\/code> checks that every package in the module compiles. Many teams run it in CI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18. What is the build cache?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go saves compiled packages in a cache folder, shown by <code>go env GOCACHE<\/code>. Next time, it only rebuilds what changed. You can clear it with <code>go clean -cache<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19. How do you put many programs in one repository?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Give each program its own folder under <code>cmd<\/code>, such as <code>cmd\/api\/main.go<\/code> and <code>cmd\/worker\/main.go<\/code>. Then run one with <code>go run .\/cmd\/api<\/code>. Shared code goes in other packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20. What exit code does a Go program return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns 0 when <code>main<\/code> finishes normally. A panic that is not recovered returns 2. You can set any code with <code>os.Exit(n)<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21. How can you see the build steps Go runs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>go build -x<\/code> to print every command, or <code>go build -v<\/code> to print package names. These flags help when a build behaves strangely.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This task shows you how to run a Go program with real input. Write a program that takes two numbers from <code>os.Args<\/code>, adds them and prints the sum. If the user gives fewer than two numbers, print a message and exit with code 1. Hint: use <code>strconv.Atoi<\/code> to turn text into an int.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/doc\/tutorial\/getting-started\">Tutorial: Get started with Go<\/a><\/li>\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/tutorial\/compile-install\">Compile and install the application<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/cmd\/go\">go command documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/os\">os package documentation<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To run a Go program quickly, use <code>go run .<\/code> inside your module folder.<\/li>\n\n\n<li><code>go build<\/code> saves a binary in the current folder, and <code>go install<\/code> puts it in GOBIN.<\/li>\n\n\n<li><code>os.Args<\/code> holds command line arguments, and <code>os.Exit<\/code> sets the exit code.<\/li>\n\n\n<li><code>go fmt<\/code> and <code>go vet<\/code> keep code clean and catch hidden bugs.<\/li>\n\n\n<li>Unused imports and variables are compile errors in Go.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can now run any program on your own machine. Next, we look at browser tools in <a href=\"https:\/\/smitabharat.com\/blog\/online-go-compilers\/\">the best online Go compilers<\/a>, so you can test code without any setup. For more basics practice, see our <a href=\"https:\/\/smitabharat.com\/blog\/go-functions-beginners-guide\/\">Go functions guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To run a Go program, you use one of three commands: go run, go build or go install. Each one compiles your code, but&hellip;<\/p>\n","protected":false},"author":1,"featured_media":694,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[106],"tags":[96,60,11,104,21],"swapz_series":[],"class_list":["post-704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-programs","tag-beginner","tag-go-build","tag-go-lang","tag-go-programs","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Run a Go Program: go run, go build, go install<\/title>\n<meta name=\"description\" content=\"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Run a Go Program: go run, go build, go install\" \/>\n<meta property=\"og:description\" content=\"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-03T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-28T19:59:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"How to Run a Go Program: go run, go build and go install\",\"datePublished\":\"2026-10-03T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/\"},\"wordCount\":2253,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/how-to-run-a-go-program-featured.png\",\"keywords\":[\"Beginner\",\"Go Build\",\"Go Lang\",\"Go Programs\",\"Golang Basics\"],\"articleSection\":[\"Go Programs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/\",\"name\":\"Run a Go Program: go run, go build, go install\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/how-to-run-a-go-program-featured.png\",\"datePublished\":\"2026-10-03T07:30:00+00:00\",\"dateModified\":\"2026-11-28T19:59:45+00:00\",\"description\":\"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/how-to-run-a-go-program-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/how-to-run-a-go-program-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Run a Go Program featured image: terminal showing go run and go build\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/how-to-run-a-go-program\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Run a Go Program: go run, go build and go install\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Run a Go Program: go run, go build, go install","description":"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/","og_locale":"en_US","og_type":"article","og_title":"Run a Go Program: go run, go build, go install","og_description":"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.","og_url":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-03T07:30:00+00:00","article_modified_time":"2026-11-28T19:59:45+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"How to Run a Go Program: go run, go build and go install","datePublished":"2026-10-03T07:30:00+00:00","dateModified":"2026-11-28T19:59:45+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/"},"wordCount":2253,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png","keywords":["Beginner","Go Build","Go Lang","Go Programs","Golang Basics"],"articleSection":["Go Programs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/","url":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/","name":"Run a Go Program: go run, go build, go install","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png","datePublished":"2026-10-03T07:30:00+00:00","dateModified":"2026-11-28T19:59:45+00:00","description":"Learn how to run a Go program with go run, go build and go install, pass arguments, use exit codes and answer common interview questions.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/how-to-run-a-go-program-featured.png","width":2400,"height":1260,"caption":"Run a Go Program featured image: terminal showing go run and go build"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/how-to-run-a-go-program\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Run a Go Program: go run, go build and go install"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=704"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/704\/revisions"}],"predecessor-version":[{"id":866,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/704\/revisions\/866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/694"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=704"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}