Install go2 beta on MacOS

A quick guide on installing golang v2 development revision.
It works for my MacOS Big Sur (with an Intel processor).

cd ~/Downloads
git clone https://go.googlesource.com/go goroot
cd ./goroot
git checkout dev.go2go
cd ./src
CGO_ENABLED=0 ./all.bash
# optional, if you see "xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun"
xcode-select --install

Save somewhere the values of the following environment variables:

echo $PATH
echo $GOROOT

Then change your environment variables like that:

export PATH=$HOME/Downloads/goroot/bin:$PATH
export GOROOT=$HOME/Downloads/goroot

Then create a file somewhere and name it main.go2

package main

import "fmt"

func main() {
	fmt.Printf("hello, world\n")
}

You should be able to run it with

go tool go2go run ./main.go2

To revert back to your regular golang v1, change the vars back to:

export PATH=$HOME/bin:/usr/local/bin:~/go/bin:$PATH (as it was for me before)
export GOROOT=$HOME/.gvm/gos/go1.15.5 (as it was for me before)

Useful links:

LEAVE A COMMENT