2013-09-21 wcdj
1 golang简介
Go is an open source programming environment that makes it easy to build simple, reliable, and efficient software.
golang的主页:http://golang.org/
2 Mac OS X 10.8.4环境安装
(1) 下载安装包(详细可参考:http://golang.org/doc/install)
https://code.google.com/p/go/wiki/Downloads?tm=2 下载页面
(2) 安装
打开下载好的pkg文件,根据安装向导完成安装。默认的安装路径是:/usr/local/go。
mba:go gerryyang$ pwd
/usr/local/go
mba:go gerryyang$ ls
AUTHORS PATENTS api doc lib robots.txt
CONTRIBUTORS README bin favicon.ico misc src
LICENSE VERSION blog include pkg test
(3) 设置环境变量
将/usr/local/go/bin添加到PATH环境变量中:
a. 在home目录下打开.bashrc文件,并将添加:export PATH=$PATH:/usr/local/go/bin,然后保存关闭;
b. 执行 . .bashrc 使环境变量生效;
在command line测试会显示如下内容:
mba:~ gerryyang$ go
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
c calling between Go and C/C++
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
mba:~ gerryyang$
3 测试
下面使用MacVim编辑:
package main
import "fmt"
func main() {
fmt.Printf(