My days of...

生活のことなど、がんばろう

Go langをMac OS Xにインストールした

Mac OS XでGoをインストールしたメモ

Homebrewを使用

brew install goでインストール

brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.4.2.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring go-1.4.2.yosemite.bottle.1.tar.gz
==> Caveats
As of go 1.2, a valid GOPATH is required to use the `go get` command:
  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.4.2: 4566 files, 155M

 

go version としてバージョン確認
go version go1.4.2 darwin/amd64

 

GOPATHとGOROOTを設定

.bash_profileに記入

export GOROOT=/usr/local/opt/go/libexec
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

 

GOPATHはなんかWORKSPACEみたいなものという理解。source .bash_profileしなくてもいいのかな・・・

$HOME/goのフォルダにhelloworld.goを作成

package main

import "fmt"

func main() {
  fmt.Println("Hello, Go World")
}

 ターミナルで$HOME/goに移動し、go run helloworld.goとすると、動いたので多分OKかな。。。

 

基礎からわかる Go言語

基礎からわかる Go言語