环境变量配置
Windows
GOROOT
GOROOT = D:\ProgramDev\Go
GOROOT
GOROOT = D:\WorkSpace\goProjects
GOBIN
GOBIN = D:\WorkSpace\goProjects\bin
Path
Path = D:\ProgramDev\Go\bin
测试环境变量
$ go env
set GOARCH=amd64
set GOBIN=D:\WorkSpace\goProjects\bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\WorkSpace\goProjects
set GORACE=
set GOROOT=D:\ProgramDev\Go
set GOTOOLDIR=D:\ProgramDev\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
编写代码
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello World!")
}
运行程序
$ go run hello.go
Hello World!
Linux
编辑.profile
vim /home/vagrant/.profile
# 添加
export GOROOT=/usr/local/go
export GOPATH=/home/vagrant/workspace/goProjects/learn-go/
export GOBIN=/home/vagrant/workspace/goProjects/learn-go/bin
export PATH=$PATH:$GOROOT/bin:$GOBIN
测试环境变量
vagrant@debian:~$ go env
GOARCH="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"
运行程序
vagrant@debian:~/workspace/goProjects/src/awesomeGo$ go run hello.go
Hello World!
有疑问加站长微信联系(非本文作者)