Reference : https://golang.org/
What is Go language?
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
How to set up host environment?
You can download installation binary file or you can building from source
https://golang.org/dl/
Download Go distribution
https://golang.org/doc/install
Installing Go from source
https://golang.org/doc/install/source
I will install from source on Ubuntu 16.04 amd64(x86-64)
Download source
git clone https://go.googlesource.com/go
cd go
git checkout go1.8 or git checkout master ( I will use stable version go1.8 branch)
Try to install
I have got an error like this.
./all.bash ##### Building Go bootstrap tool. cmd/dist ERROR: Cannot find /home/jinseo/go1.4/bin/go. Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4. |
Resolve the issue
$ GOOS=linux GOARCH=amd64 ./bootstrap.bash
#### Copying to ../../go-linux-amd64-bootstrap
#### Cleaning ../../go-linux-amd64-bootstrap
#### Building ../../go-linux-amd64-bootstrap
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /usr/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
I have to install go cross compiler
$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
update-alternatives: error: no alternatives for go
--> I made a soft link
You can skip this part to run bootstrap.bash
After made a soft link I ran again $ GOOS=linux GOARCH=amd64 ./bootstrap.bash ../../go-linux-amd64-bootstrap already exists; remove before continuing
I deleted the directory $ rm -rf ../../go-linux-amd64-bootstrap/
Ran again $ GOOS=linux GOARCH=amd64 ./bootstrap.bash
...... Bootstrap toolchain for linux/amd64 installed in /home/jinseo/work/golang/go-linux-amd64-bootstrap. Building tbz. -rw-rw-r-- 1 jinseo jinseo 55474955 Mar 1 05:55 /home/jinseo/work/golang/go-linux-amd64-bootstrap.tbz
Build was finished successfully. |
$ ./all.bash
......
Installed Go for linux/amd64 in /home/jinseo/work/golang/go
Installed commands in /home/jinseo/work/golang/go/bin
*** You need to add /home/jinseo/work/golang/go/bin to your PATH.
I removed the soft link (/usr/bin/go) and I added /home/jinseo/work/golang/go/bin to PATH.
Run test program
hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
jinseo@jinseo-desktop:~/work/golang/go/src$ vi hello.go
jinseo@jinseo-desktop:~/work/golang/go/src$ go run hello.go