fugafuga.write

日々のログ

MacOSX に Go 言語の環境を準備する

Go 言語を触るため。

環境

Mac OSX 10.11

インストール

Homebrew でインストールする

% brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.5.1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.5.1.el_capitan.bottle.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.5.1: 5330 files, 273M

バージョン確認

% go version
go version go1.5.1 darwin/amd64

hello world する

[ hello.go ]

package main

import (
  "fmt"
)

func main() {
  fmt.Println("hello world")
}

実行

% go run hello.go
hello world

go run で コンパイル と 実行 を両方やってくれるみたい。

コンパイルは、go build

% go build hello.go
% ls
hello    hello.go

バイナリができる。

改訂2版 基礎からわかる Go言語

改訂2版 基礎からわかる Go言語

はじめての「Go言語」 (I・O BOOKS)

はじめての「Go言語」 (I・O BOOKS)