Go言語の勉強をするにあたってMacBookPro(2018) High Sierraに開発環境を構築したのでメモ
前提条件
パッケージマネージャーはHomebrewを使用し、既にインストール済みの環境が前提となります。
Goのインストール(Homebrew)
$ brew install go Updating Homebrew... ==> Auto-updated Homebrew! Updated 2 taps (homebrew/core, homebrew/cask). ==> New Formulae carla hyperkit peru picat skopeo ucloud vfuse ==> Updated Formulae ・ ・ 〜 中略 〜 ・ ・ ==> Deleted Formulae llvm@3.7 mediatomb ==> Downloading https://homebrew.bintray.com/bottles/go-1.11.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring go-1.11.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.11: 9,273 files, 403.9MB
・インストールおよびバージョン確認
$ go version go version go1.11 darwin/amd64
環境変数の設定
環境変数にて各種パッケージをダウンロードするディレクトリを指定します
$ export GOPATH=$HOME/.go $ export PATH=$PATH:$GOPATH/bin
以上、Go開発環境の構築は完了です。
Hello World(動作確認)
動作確認の為にHello Worldを出力するプログラムを作成し実行します$ vi hello.go ### hellog.go ### package main import "fmt" func main() { fmt.Printf("Hello World!\n") }
・実行
$ go run hello.go Hello World!
以上で完了となります。