Karena saya ingin belajar dan fokus ke Golang (bukan Go Seiba) maka berikut adalah dokumentasi install Golang di Ubuntu 18.04 beserta simple script hello world di Golang.

Download

  • Download go1.13.1.
    curl -O https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz
  • Ekstrak go ke /usr/local.
    sudo tar -xvf go1.13.1.linux-amd64.tar.gz -C /usr/local
  • Change owner go files.
    sudo chown -R root:root /usr/local/go

    Kenapa di ganti ke root? Karena untuk memastikan file go binary hanya bisa dijalankan oleh root.

Set Up Go Workspace

  • Create go di $HOME.
    mkdir -p $HOME/go/{bin,src}
  • Set Up $GOPATH.
    sudo vim ~/.profile

    # GOPATH
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    export PATH=$PATH:$GOPATH/bin:/usr/local/go/bin
  • Reload ~/.profile.
    . ~/.profile
  • Verify install.
    go version

    Expected output:
    go version go1.13.1 linux/amd64

The Boring Hello World

  • Create hello-world.go file.
    vim hello-world.go

    package main
    import "fmt""
    func main() {
        fmt.Println("Hello, World!")
    }
  • Run hello-world.go file.
    go run hello-world.go

    Output:
    Hello, World!

Last modified: October 3, 2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.