5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MacでのGo言語のインストール

Last updated at Posted at 2015-02-21

2/9のGolangチュートリアルもくもく会@ギークハウス秋葉原にて
基本的にソースからのGo言語インストール - golang.jp 1に従ってインストールした。

事前にXcodeのインストールが必要っぽい。

  • 1−1、Mercurialのインストール

Mercurial SCMから.dmgファイルでインストールした。2

  • 1−2、Mercurialのインストール

1−1だけで十分だったっぽい?けど打った。

$ sudo easy_install mercurial==2.0

  • 2、リポジトリからの取得

$ hg clone -u release https://code.google.com/p/go

  • 3、Go言語のインストール

少し時間がかかる。ALL TESTS PASSEDが出てくる。

$ cd go/src
$ ./all.bash

フルパス入力などで、パスを通さないで
実行するならそのままhello, World。

  • 4、パスを通す

オプション環境変数の項を参照
私の環境がMac OS X 10.9.5の64bit OSだったので、
GOOSはdarwin(Mac OS X 10.6以降)、
GOARCHはamd64(64bit x86)になった。
GOROOTは2、リボジトリからの取得で取得されたGo言語のフォルダのパスを入力する。
私の場合は環境変数$HOME3の直下に置いたので
GOROOTは$HOME/goになった。
GOPATHはgit install hogehogeでダウンロードしたgo言語のライブラリのパスになるっぽい。
PATH=$PATH:hogehogeで環境変数$PATHに追加されるのが一番重要ぽい。
$GOBINは$GOROOT/binと等価っぽい、入れなくて良さげ。

.bashrc
# for Golang
export GOROOT=$HOME/go
export GOARCH=amd64
export GOOS=darwin

export GOBIN=$HOME/go/bin
export GOPATH=$HOME/_go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin:$GOBIN
  • 5、実行またはコンパイル

実行は

$go run hello.go

コンパイルは

$go build hello.go

で実行ファイルが生成される。
6g, gccgo, 6l, 6c, 6aなどあるが
今回インストールしたバージョン1.4では
変更されている模様。

  • 6、その他

最新リリースを保つの項を行うと

$ cd go/src
$ hg pull
$ hg update release
$ ./all.bash

コマンドファイルが移動するか消去されるので
動作しなくなる。

$ rm runtime/*
$ rmdir runtime

でruntimeフォルダを消去して再インストールしたら
復帰できた。

  1. Go言語のバージョン1.0、1.1のときの翻訳なので、情報が古くて合わないところがある。

  2. homebrewからもインストールできる模様

  3. echo_$HOMEでフルパスが出力される。
    .bashrcに以下を追加した。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?