colinux(Debian)でgo

colinux(Debian)にGoを入れてみる手順です。

インストール

rootでeasy_installとmercurialと、必要なコマンドとライブラリをインストールします。

# aptitude install python-dev
# aptitude install python-setuptools python-docutils
# easy_install mercurial
# aptitude install bison gcc libc6-dev ed time

ユーザに戻り、goをインストールします。
~/binが既にあり、PATHが通ってるならmkdir ~/binexport PATH=$HOME/bin:$PATHを抜いてください。

$ export GOROOT=$HOME/go
$ export GOOS=linux
$ export GOARCH=386
$ mkdir ~/bin
$ export PATH=$HOME/bin:$PATH
$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT
$ cd $GOROOT/src
$ ./all.bash

~/binに8g,8l等ができているはずです。
~/.bashrcに設定を追加します。

export GOROOT=$HOME/go
export GOOS=linux
export GOARCH=386
export PATH=$HOME/bin:$PATH

一応source ~/.bashrcを通して確認しておきます。

こんにちは世界

適当にディレクトリを作り、helloworld.goをutf-8で作成します。

package main
import fmt "fmt"

func main(){
	fmt.Printf("ごきげんよう 言葉様\n");
}

コンパイル、リンク、実行します。

$ 8g helloworld.go
$ 8l helloworld.8
$ ./8.out
ごきげんよう 言葉様

Nice boat.

リファレンス

コマンドラインから:

$ godoc パッケージ名 関数名