Mac に GO言語(golang)をインストールしてみる。

Googleが新しい言語(go言語)を開発したって事なので、せっかくなので
インストールしてみます。

http://golang.org/doc/install.html

に、インストールマニュアルがありますが、今回は
Mac OS 10.6.2 (Snow Leopard)へのインストール記録

0.下準備
今回は、一ユーザの権限でインストールします。
下準備

  • Xcode をインストールしている。(OSのインストールディスクからインストールできます)
  • macportsが入っている。
  • 基本のディレクトリは、/Users/kiyo(おのおののユーザ名で置き換えてください)とする。
  • ターミナルの作業が基本です。
  • goのインストールフォルダは、/Users/kiyo/go とします。

1.Environment variables 環境変数を設定する。
ターミナルを立ち上げて、

KiyoMac:~ kiyo$ cd
KiyoMac:~ kiyo$ vi .bash_profile

下記の行を追加

export GOROOT=$HOME/go
export GOOS=darwin
export GOARCH=amd64
export GOBIN=$GOROOT/bin
export PATH=$GOBIN:$PATH

※10.5.x(Leopard)の場合は、32bitかもしれないので。

export GOARCH=386

でないといけないとおもいます。(未検証)
反映

KiyoMac:~ kiyo$ source .bash_profile

確認

KiyoMac:~ kiyo$ env | grep ‘^GO’
GOBIN=/Users/kiyo/go/bin
GOARCH=amd64
GOROOT=/Users/kiyo/go
GOOS=darwin

パスに設定されてるかも確認

KiyoMac:~ kiyo$ env | grep ‘^PATH’
PATH=/Users/kiyo/go/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

/Users/kiyo/go/bin があればOK

2.Ports
GO言語は、LinuxとMac OS X で、それぞれ、amd64(64bit) 386(32bit) arm に対応してるよってことなので、無視。

3.Fetch the repository レポジトリの作成まぁ、インストールフォルダの作成。
まず、hg のコマンドがあるか確認します。

KiyoMac:~ kiyo$ which hg
/usr/local/bin/hg

で、コマンドが出てこない場合は、

KiyoMac:~ kiyo$ sudo easy_install mercurial
Password:
Searching for mercurial
Reading http://pypi.python.org/simple/mercurial/
Reading http://www.selenic.com/mercurial
Best match: mercurial 1.3.1
Downloading http://mercurial.selenic.com/release/mercurial-1.3.1.tar.gz
Processing mercurial-1.3.1.tar.gz
Running mercurial-1.3.1/setup.py -q bdist_egg –dist-dir /tmp/easy_install-Ui4ZEE/mercurial-1.3.1/egg-dist-tmp-SbX7Oy
zip_safe flag not set; analyzing archive contents…
mercurial.extensions: module references __file__
mercurial.i18n: module references __file__
mercurial.lsprof: module references __file__
mercurial.templater: module references __file__
Adding mercurial 1.3.1 to easy-install.pth file
Installing hg script to /usr/local/bin

Installed /Library/Python/2.6/site-packages/mercurial-1.3.1-py2.6-macosx-10.6-universal.egg
Processing dependencies for mercurial
Finished processing dependencies for mercurial

でいれこみます。入る物は、
http://mercurial.selenic.com/wiki/Download
です。
フォルダがなければ

KiyoMac:~ kiyo$ mkdir ./go

で作成。
ソース等の入れ込み

KiyoMac:~ kiyo$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT
requesting all changes
adding changesets
adding manifests
adding file changes
added 3976 changesets with 16799 changes to 2931 files
updating working directory
1640 files updated, 0 files merged, 0 files removed, 0 files unresolved

4.Install Go インストール
じゃあインストールしてみましょう。ここでOS Xに、Xcodeが入ってないと、gccとかがないので
コンパイルできずに怒られるので、先にXcodeを入れておいてください。

KiyoMac:~ kiyo$ cd go/src/
KiyoMac:src kiyo$ ./all.bash
色々出てきて。
— cd ../test
0 known bugs; 0 unexpected bugs

終了

5.Writing programs プログラムを書こう
じゃあ、プログラムを動かしてみましょう。
Mac OS X 10.6 は、6g 6l のコマンドを利用します。OS X 10.5(32bit)なら、8g 8l みたいです。(未確定)

KiyoMac:~ kiyo$ cd
KiyoMac:~ kiyo$ cat hello.go
package main

import “fmt”

func main() {
fmt.Printf(”hello, world\n”)
}
KiyoMac:~ kiyo$ 6g hello.go
KiyoMac:~ kiyo$ 6l hello.6
KiyoMac:~ kiyo$ ./6.out
hello, world

と出力されればインストール完了です。

さて、問題はこれでなにをするかだ・・・。

2009.11.11

Category: Mac / Tags:

Comments (1)

Go言語をインスト

11月 15th, 2009 at 13:56    


[...]  ・Mac に GO(golang)をインストールしてみる。 [...]

Leave a reply

Name *

Mail *

Website