ยง2023-07-12

  1. Install go From Precompiled Binary
$ sudo apt remove  golang-go (pacman -Rns go)
$ wget https://go.dev/dl/go1.20.6.linux-arm64.tar.gz
$ sudo rm -rf /usr/local/go && sudo tar -C /usr/local  -xvzf go1.20.6.linux-arm64.tar.gz

Add into /.bashrc and source /.bashrc` ``

go env

PATH=/usr/local/go/bin:$PATH


```bash
$ source ~/.bashrc
$ go version
go version go1.20.6 linux/arm64
  1. Write your first hello.go
$ mkdir -p go-proj/hello && cd $_

When your code imports packages contained in other modules, you manage those dependencies through your code's own module. That module is defined by a go.mod file that tracks the modules that provide those packages. That go.mod file stays with your code, including in your source code repository.

To enable dependency tracking for your code by creating a go.mod file, run the go mod init command, giving it the name of the module your code will be in. The name is the module's module path.

In actual development, the module path will typically be the repository location where your source code will be kept. For example, the module path might be github.com/mymodule. If you plan to publish your module for others to use, the module path must be a location from which Go tools can download your module. For more about naming a module with a module path, see Managing dependencies.

For the purposes of this tutorial, just use example/hello.

$ pwd
/opt/xfs/home/alexlai/go-proj/hello

$ go mod init example/hello
go: creating new go.mod: module example/hello
alexlai@org5Bookworm:~/go-proj/hello$ tree
.
โ””โ”€โ”€ go.mod

1 directory, 1 file

$ cat go.mod 
module example/hello

go 1.20

hello.go as

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
$ go run hello.go 
Hello, World!