Golang: Compile and Run

By Xah Lee. Date: . Last updated: .

Copy and paste the following into a file, name the file “test.go”.

package main

import "fmt"

func main() {
        fmt.Println("i love cats")

To run go program, in terminal type go run test.go

To compile go program, in terminal type go build test.go

This will create a compiled file named “test”.

Compiled file can be run directly, for example ./test

Golang Topics

  1. Compile, Run
  2. Package, Import
  3. Function
  4. Variable
  5. Constant
  6. If Then Else
  7. switch/case
  8. Loop
  9. Basic Types
  10. Array
  11. Slice
  12. map

Ask me question on patreon