brew install go
Create directories for GOPATH:
mkdir ~/go
mkdir ~/go/src
Add to .bash_profile
export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/go
export PATH="$GOPATH/bin:$PATH"
Download the latest distribution:
curl -O https://storage.googleapis.com/golang/go1.10.linux-amd64.tar.gz
Unpack it to the /usr/local
sudo tar -C /usr/local -xzf go1.10.linux-amd64.tar.gz
For Go to work properly, you need to set the following two environment variables:
Setup a go folder
mkdir -p ~/go; echo "export GOPATH=$HOME/go" >> ~/.bashrc
Update your path
echo "export PATH=$PATH:$HOME/go/bin:/usr/local/go/bin" >> ~/.bashrc
Read the environment variables into current session:
source ~/.bashrc
GOOS=linux GOARCH=amd64 go build hello_world.go
GOOS=darwin GOARCH=amd64 go build hello_world.go
GOOS=windows GOARCH=amd64 go build hello_world.go
GOOS=windows GOARCH=386 go build hello_world.go
GOOS=linux GOARCH=arm go build hello_world.go
List supported platforms:
go tool dist list