Go 开发环境配置

2018-07-17  本文已影响62人  faremax

Golang是Google开发的一种编译型,平行化编程语言。具有简洁、快速、安全。善于内存管理、数组安全,并且编译迅速
Go语言设计支持主流的32位和64位的x86平台,同时也支持32位的ARM架构。Go语言在Go1版本上支持Windows, 苹果Mac OS X, Linux和FreeBSD操作系统。

当然,一切语言的学习都从搭建环境开始(macOS)

使用 HomeBrew 安装

Homebrew 安装参考:http://brew.sh/

$ brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.10.3.high_sierra.bottl
Already downloaded: /Users/faremax/Library/Caches/Homebrew/go-1.10.3.high_sierra.bottle.tar.gz
==> Pouring go-1.10.3.high_sierra.bottle.tar.gz
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
  https://golang.org/doc/code.html#GOPATH

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺  /usr/local/Cellar/go/1.10.3: 8,170 files, 336.7MB

安装成功后需要配置一下环境变量,在~/.bash_profile中添加以下内容:

#golang
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN

这里可以看出需要设置GOPATH和GOBIN的环境变量,以及设置PATH.

为使修改立刻生效,执行:

$ source .bash_profile

查看配置是否生效:

$ go env

得到如下内容:

GOARCH="amd64"
GOBIN="/Users/faremax/go/bin"
GOCACHE="/Users/faremax/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/faremax/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"GOARCH="amd64"
GOBIN="/Users/faremax/go/bin"
GOCACHE="/Users/faremax/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/faremax/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f0/wl0qf7mn1131dc3brmbb3_d00000gn/T/go-build994213970=/tmp/go-build -gno-record-gcc-switches -fno-common"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/f0/wl0qf7mn1131dc3brmbb3_d00000gn/T/go-build994213970=/tmp/go-build -gno-record-gcc-switches -fno-common"

可以看到,配置生效,环境变量设置完成!

上一篇下一篇

猜你喜欢

热点阅读