Go 開發環境配置

來源:互聯網
上載者:User

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.bottlAlready 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==> CaveatsA 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#GOPATHYou 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中添加以下內容:

#golangexport GOPATH=$HOME/goexport GOBIN=$GOPATH/binexport 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"

可以看到,配置生效,環境變數設定完成!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.