Golang Installation and Configuration
Download the installation file, currently the latest version is 1.4.2,go1.4.2.linux-amd64.tar.gz.
Extract the installation files to the specified directory:
1 sudo tar -zxvf go1. 4.2. Linux-amd64. tar. Gz-c/usr/local/
Edit the/etc/profile file to add an environment variable:
Export Goroot=/usr/local/goexport gobin= $GOROOT/binexport path= $PATH: $GOBINexport gopath= $HOME/goproj
Recompile the/etc/profile file and try to view the go version:
1 # source/etc/Profile2 # Go version
Golang Cross-compiling
Create a new Hello.go file with the following contents:
1 package main 2 import ( 4 fmt " 5 ) 7 func Main () { 8 fmt . Println ( hello golang! " ) 9 }
The go installation package only packages the compilation tools under the corresponding platform, for cross-compiling, you need to manually build the other platform's compilation tools. The following generates the Windows 64-bit compiler, opens/usr/local/go/src/, executes the following code, GOOS represents the target system type, Goarch indicates that the target system is 32-bit (386) or 64-bit (AMD64):
1 # sudo goos=windows goarch=amd64./make.bash
After the command executes successfully, the compiler tool for the appropriate platform is generated under/usr/local/go/pkg/.
Next, select the corresponding target platform in Liteide, compile the Go program code, the result is as follows:
Finally attach each platform GOOS and Goarch reference:
GOOS |
Goarch |
OS |
Linux |
386/amd64/arm |
>= Linux2.6 |
Darwin |
386/amd64 |
OS X (Snow Leopard + Lion) |
Freebsd |
386/amd64 |
>= FreeBSD 7 |
Windows |
386/amd64 |
>= Windows 2000 |
Setting up Golang development environment under Ubuntu