This is a creation in Article, where the information may have evolved or changed.
Environment variable Configuration
Windows
Goroot
GOROOT = D:\ProgramDev\Go
Goroot
GOROOT = D:\WorkSpace\goProjects
GOBIN
GOBIN = D:\WorkSpace\goProjects\bin
Path
Path = D:\ProgramDev\Go\bin
Test environment variables
$ go envset GOARCH=amd64set GOBIN=D:\WorkSpace\goProjects\binset GOEXE=.exeset GOHOSTARCH=amd64set GOHOSTOS=windowsset GOOS=windowsset GOPATH=D:\WorkSpace\goProjectsset GORACE=set GOROOT=D:\ProgramDev\Goset GOTOOLDIR=D:\ProgramDev\Go\pkg\tool\windows_amd64set GCCGO=gccgoset CC=gccset GOGCCFLAGS=-m64 -mthreads -fmessage-length=0set CXX=g++set CGO_ENABLED=1set CGO_CFLAGS=-g -O2set CGO_CPPFLAGS=set CGO_CXXFLAGS=-g -O2set CGO_FFLAGS=-g -O2set CGO_LDFLAGS=-g -O2set PKG_CONFIG=pkg-config
Writing code
package mainimport ( "fmt")func main() { fmt.Println("Hello World!")}
Run the program
$ go run hello.goHello World!
Linux
Edit.profile
vim /home/vagrant/.profile# 添加export GOROOT=/usr/local/goexport GOPATH=/home/vagrant/workspace/goProjects/learn-go/export GOBIN=/home/vagrant/workspace/goProjects/learn-go/binexport PATH=$PATH:$GOROOT/bin:$GOBIN
Test environment variables
vagrant@debian:~$ go envGOARCH="amd64"GOBIN="/home/vagrant/workspace/goProjects/learn-go/bin"GOEXE=""GOHOSTARCH="amd64"GOHOSTOS="linux"GOOS="linux"GOPATH="/home/vagrant/workspace/goProjects/learn-go/"GORACE=""GOROOT="/usr/local/go"GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"GCCGO="gccgo"CC="gcc"GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build955111107=/tmp/go-build -gno-record-gcc-switches"CXX="g++"CGO_ENABLED="1"CGO_CFLAGS="-g -O2"CGO_CPPFLAGS=""CGO_CXXFLAGS="-g -O2"CGO_FFLAGS="-g -O2"CGO_LDFLAGS="-g -O2"PKG_CONFIG="pkg-config"
Run the program
vagrant@debian:~/workspace/goProjects/src/awesomeGo$ go run hello.go Hello World!