How To Install Golang compiler on Ubuntu
$ sudo curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
$ sudo tar -xvf go1.6.linux-amd64.tar.gz
$ sudo mv go /usr/local
$ sudo vim ~/.profile
At the end of the file, add this line:
export PATH=$PATH:/usr/local/go/bin
$ export GOROOT=$HOME/go
$ export PATH=$PATH:$GOROOT/bin
$ source ~/.profile
Create a new directory for your Go workspace, which is where Go will build its files.
$ mkdir $HOME/work
$ export GOPATH=$HOME/work
$ mkdir -p work/src/github.com/user/hello
$ vim work/src/github.com/user/hello/hello.go
Inside your editor, paste in the content below, which uses the main Go packages,
imports the formatted IO content component,
and sets a new function to print 'Hello World' when run.
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
compile it invoking the Go command install.
$ go install github.com/user/hello
The file compiled, you can run it by simply referring to the file at your Go path.
$ sudo $GOPATH/bin/hello
Comments
Post a Comment