golang install for mac

 

转自 http://www.kelvinwong.ca/2009/11/12/installing-google-go-on-mac-os-x-leopard/

To get started, make sure that you have Python and Mercurial installed on your Intel Mac (PowerPC is not supported at this point). Also make sure that you have XCode installed and that you are attached to the Internet (the test suite will need Internet access to run a few tests).

Trinity:~ kelvin$ python -V
Python 2.5.2
Trinity:~ kelvin$ hg version
Mercurial Distributed SCM (version 1.0.1)

 

Copyright (C) 2005-2008 Matt Mackall <[email protected]> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trinity:~ kelvin$ xcodebuild -version
Xcode 3.1.2
Component versions: DevToolsCore-1148.0; DevToolsSupport-1102.0
BuildVersion: 9M2621
Trinity:~ kelvin$ uname -p
i386
Trinity:~ kelvin$

Okay, now we’re going to make some environment variables that Go will use to compile your code. In my home directory, I put the following variables into the ‘.bash_profile’ file:

#GOROOT="/usr/local/go"

#GOBIN=""

#GOARCH="386"

#GOCHAR="8"

#GOOS="darwin"

#GOEXE=""

#GOHOSTARCH="386"

#GOHOSTOS="darwin"

#GOTOOLDIR="/usr/local/go/pkg/tool/darwin_386"

#GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread -fno-common"

#CGO_ENABLED="1"

# Google Go Lang Vars
export GOROOT=$HOME/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
export PATH=$GOBIN:$PATH

Now we make sure that the environment has the variables we just set up:

Trinity:~ kelvin$ source .bash_profile
Trinity:~ kelvin$ env | grep ^GO
GOBIN=/Users/kelvin/bin
GOARCH=386
GOROOT=/Users/kelvin/go
GOOS=darwin
Trinity:~ kelvin$

Make sure that your ‘~/go’ directory doesn’t exist since the next command will make it into a Mercurial repository. We will be creating the ‘~/bin’ directory after we create the repository.

 

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

或者 Trinity:~ kelvin$ 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
Trinity:~ kelvin$ cd $GOROOT
Trinity:go kelvin$ ls
AUTHORS LICENSE doc include misc src
CONTRIBUTORS README favicon.ico lib pkg test
Trinity:go kelvin$ cd src/
Trinity:src kelvin$

Okay, so far we have set-up the environment and the respository. Now would be a good time to ensure the ‘~/bin’ folder actually exists. In many cases, it is already there. If it isn’t there, you need to create it and mark it executable (Hint: Try ‘mkdir ~/bin’ then ‘chmod 755 ~/bin’).

Trinity:src kelvin$ test -e ~/bin && echo 'bin exists'
bin exists
Trinity:src kelvin$

Okay, now we’re ready to build Go.

Trinity:src kelvin$ ./all.bash 
rm -f *.o *.6 6.out lib9.a
rm -f bbuffered.o bfildes.o bflush.o bgetc.o bgetrune.o bgetd.o binit.o boffset.o bprint.o bputc.o bputrune.o brdline.o brdstr.o bread.o bseek.o bwrite.o *.6 6.out libbio.a
rm -f *.o *.so
.... holy crap there is a lot of output here...
./mkasmh.sh >386/asm.h.x
mv -f 386/asm.h.x 386/asm.h
8a 386/asm.s
8c -Idarwin -Idarwin/386 -wF cgocall.c
8c -Idarwin -Idarwin/386 -wF chan.c
8c -Idarwin -Idarwin/386 -wF 386/closure.c
8c -Idarwin -Idarwin/386 -wF float.c
8c -Idarwin -Idarwin/386 -wF hashmap.c
8c -Idarwin -Idarwin/386 -wF iface.c
quietgcc -o cgo2c cgo2c.c
./cgo2c malloc.cgo > malloc.c.tmp
mv -f malloc.c.tmp malloc.c
...Two peanuts were walking down the street. One was a salted...
8g -I_obj main.go
8l -L_obj -o ogle main.8

real 0m0.996s
user 0m0.831s
sys 0m0.148s

--- cd ../doc/progs

real 0m2.229s
user 0m1.714s
sys 0m0.431s

--- cd ../test/bench
fasta
reverse-complement
nbody
binary-tree
binary-tree-freelist
fannkuch
regex-dna
spectral-norm
k-nucleotide
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux

 

--- cd ../test
0 known bugs; 0 unexpected bugs
Trinity:src kelvin$

Okay, so hopefully you now have a working copy of the Go programming language. You can try to find the executables on your system. Your compiler is ’8g’ if for the i386 architecture.

Trinity:~ kelvin$ which 8g
/Users/kelvin/bin/8g
Trinity:~ kelvin$ which 8l
/Users/kelvin/bin/8l
Trinity:~ kelvin$ 8g
flags:
-I DIR search for packages in DIR
-d print declarations
-e no limit on number of errors printed
-f print stack frame structure
-h panic on an error
-k name specify package name
-o file specify output file
-S print the assembly language
-w print the parse tree after typing
-x print lex tokens
Trinity:~ kelvin$

Notice that ‘gccgo’ is not installed by default; if you want to try that out you need to install it separately. Try working through the examples!


你可能感兴趣的:(Install)