這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
1、環境變數GOLANG官網介紹
$GOROOT
The root of the Go tree, often
$HOME/go
. This defaults to the parent of the directory where
all.bash
is run. If you choose not to set
$GOROOT
, you must run
gomake
instead of
make
or
gmake
when developing Go programs using the conventional makefiles.
$GOROOT_FINAL
The value assumed by installed binaries and scripts when
$GOROOT
is not set. It defaults to the value used for
$GOROOT
. If you want to build the Go tree in one location but move it elsewhere after the build, set
$GOROOT_FINAL
to the eventual location.
$GOOS
and
$GOARCH
The name of the target operating system and compilation architecture. These default to the values of
$GOHOSTOS
and
$GOHOSTARCH
respectively (described below).
Choices for $GOOS
are linux
, freebsd
, darwin
(Mac OS X 10.5 or 10.6), and windows
(Windows, an incomplete port). Choices for $GOARCH
are amd64
(64-bit x86, the most mature port), 386
(32-bit x86), and arm
(32-bit ARM, an incomplete port). The valid combinations of$GOOS
and $GOARCH
are:
$GOOS
$GOARCH
|
darwin |
386 |
|
darwin |
amd64 |
|
freebsd |
386 |
|
freebsd |
amd64 |
|
linux |
386 |
|
linux |
amd64 |
|
linux |
arm |
incomplete |
|
windows |
386 |
incomplete |
$GOHOSTOS
and
$GOHOSTARCH
The name of the host operating system and compilation architecture. These default to the local system's operating system and architecture.
Valid choices are the same as for $GOOS
and $GOARCH
, listed above. The specified values must be compatible with the local system. For example, you should not set $GOHOSTARCH
to arm
on an x86 system.
$GOBIN
The location where binaries will be installed. The default is
$GOROOT/bin
. After installing, you will want to arrange to add this directory to your
$PATH
, so you can use the tools.
$GOARM
(arm, default=6)
The ARM architecture version the run-time libraries should target. ARMv6 cores have more efficient synchronization primitives. Setting
$GOARM
to 5 will compile the run-time libraries using just SWP instructions that work on older architectures as well. Running v6 code on an older core will cause an illegal instruction trap.
Note that $GOARCH
and $GOOS
identify the target environment, not the environment you are running on. In effect, you are always cross-compiling. By architecture, we mean the kind of binaries that the target environment can run: an x86-64 system running a 32-bit-only operating system must set GOARCH
to 386
, not amd64
.
If you choose to override the defaults, set these variables in your shell profile ($HOME/.bashrc
, $HOME/.profile
, or equivalent). The settings might look something like this
export GOROOT=$HOME/goexport GOARCH=386export GOOS=linux
2、在ubuntu中配置
1)環境變數設定檔
在Ubuntu中有如下幾個檔案可以設定環境變數
1、/etc/profile:在登入時,作業系統定製使用者環境時使用的第一個檔案,此檔案為系統的每個使用者佈建環境資訊,當使用者第一次登入時,該檔案被執行。
2、/etc/environment:在登入時作業系統使用的第二個檔案,系統在讀取你自己的profile前,設定環境檔案的環境變數。
3、~/.bash_profile:在登入時用到的第三個檔案是.profile檔案,每個使用者都可使用該檔案輸入專用於自己使用的shell資訊,當使用者登入時,該 檔案僅僅執行一次!預設情況下,他設定一些環境變遊戲量,執行使用者的.bashrc檔案。/etc/bashrc:為每一個運行bash shell的使用者執行此檔案.當bash shell被開啟時,該檔案被讀取.
4、~/.bashrc:該檔案包含專用於你的bash shell的bash資訊,當登入時以及每次開啟新的shell時,該該檔案被讀取。
幾個環境變數的優先順序
1>2>3
2)開始配置,這裡配置為僅本使用者使用
liuxing@liuxing-O-E-M:~$ gedit ~/.bashrc
在後面加上
export GOROOT=$HOME/go
export GOBIN=$GOROOT/bin
export GOARCH=386
export GOOS=linux
export PATH=.:$PATH:$GOBIN
3)
liuxing@liuxing-O-E-M:~$ source ~/.bashrc
liuxing@liuxing-O-E-M:~$ 8g
gc: usage: 8g [flags] file.go...
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
-o file specify output file
-S print the assembly language
-V print the compiler version
-u disable package unsafe
-w print the parse tree after typing
-x print lex tokens