How to install Go on Mac?

·

1 min read

I decided to spend time on learning Go despite that my React is still not good. But, just to stay away from React for a while.

Installing Go is not as easy as I think. So, I think it'd better that I write it down.

Following Go install documentation

First, after installing Go on Mac, open the terminal and create a new folder called under the root directory. I will call it go-test.

$ mkdir go-test
cd go-test

Then, we will initialize go module. The module path might be github.com/mymodule.

$ go mod init go-test

Type "code ." to open vscode and create a new file called main.go.

Now, we can write the famous "Hello World" in Go.

package main

import "fmt"

func main () {
    fmt.Println("Hello World!")
}

To run go, the command line is go run "file name". So here we type "go run main.go" and we print "Hello World!" successfully!

截圖 2022-07-10 上午9.17.05.png