Setting up Golang development environment under Ubuntu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.