`

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 <mpm@selenic.com> 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!


分享到:
评论

相关推荐

    golang1.22安装包

    Go语言,通常被称为Golang,是由Google开发的一种静态类型的、编译式的、并发型且具有垃圾回收功能的编程语言。Go语言的设计目标是提高开发者的生产效率,提供简洁的语法和强大的工具链,同时保持高性能。在本安装包...

    Golang数据库管理和代码生成-Golang开发

    它具有一个命令行界面,该界面提供:SQL迁移嵌入式SQL脚本从SQL模式安装生成GitHub $ go get -u github.com/phogolabs/prana $ go install github.com/phogolabs/prana/cmd/prana Homebrew(for Mac OS X)$ brew ...

    govatar:GO语言的头像生成库

    从v0.4.0版本开始,最低支持的golang版本为1.16。 安装 酿造 $ brew tap o1egl/tap $ brew install govatar 码头工人 $ docker pull o1egl/govatar 从来源 $ go get -u github.com/o1egl/govatar/... 预构建的可用于...

    hive:一个支持众包网站的平台,内置在golang中,用于Elasticsearch

    在Mac上使用安装很简单: brew updatebrew install elasticsearch您可以在找到其他平台的。 有两个运行配置单元的选项。二元下载,解压缩并双击以开始。 hive将默认在上运行。来源这种方法将允许您破解hive源代码。...

    go1.16.3.darwin-amd64.pkg

    golang 1.16最新安装包 for mac, brew install只能装到1.12版本,要最新的只能下载安装包。 想不到这个还挺难找的。

    Go语言学习资料

    - Go语言的核心结构与技术:这里详细介绍了Go语言的核心技术细节,包括控制结构(if-else、switch、for、break与continue)、函数(参数、返回值、变长参数、闭包)、内置函数(defer、panic、recover)、面向对象...

    easyBEATS:Beats for Raspberry Pi ARM

    easyBEATS关于easyBEATS是一个项目,旨在使Ubuntu,Mac甚至Raspberry Pi(ARM体系结构)的Beats软件包的安装更加便捷。 重点是Rasperry Pi,因为Elastic在ARM体系结构上没有受支持的版本。 easyBEATS还解决了RPi apt...

    gin-rest-cqrs-example:Go,Gin,MySQL,Redis,REST api,CQRS,Swagger的示例

    安装Go: : 安装适用于MAC的Docker: : 安装适用于Windows的Docker: : //docs.docker.com/docker-for-windows/install/ 安装撰写: https : //docs.docker.com/compose/install/ 创建开发环境首先,创建目录$...

Global site tag (gtag.js) - Google Analytics