installation, compilation, and operation of Golang under Ubuntu

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

1 Introduction

In the last two years Golang is developing rapidly, and itis the most popular programming language in the next ten years, with the mainstream languages such as C + + and Java as well. In the open source community, the bustling Docker,KubernetesandCoreOS ecosystems are developed using Golang , which is Golang The best illustration of the great heat. Golang is highly respected for its unique concurrent programming model, benefiting from its more minimalist and abstract programming philosophy (interfaces,OOP, etc.). As a distributed field of developers, you cannot but focus on Golang.


2 installation

Environment: Ubuntu 14.04

sudo listen to Apt-get listen to the install listen to Golang-gosudo listen to Apt-get listen to the installation listen to Golang-go.tools listen to the installed Godoc and other tools

3 Sample Programs

Hello world, examples from Xu Xiwei and other people's translation of the "Go language programming."

Listen to Hello.gopackage listen to the main listen//listen to the package listen to Declaration,must listen to Onlyimport listen to (listen to listen to hear//listen to the import listen to packages listen to the "FMT" Listen to "OS" Listen to hear " Strings ") Listen to Func listen to main () listen {Listen to the WHO listen: = Listen to" world! " Listen if listen to Len (OS. Args) Listen to > Listen to 1 listen to listen to hear listen to listen to hear the WHO listen to listen to strings. Join (OS. Args[1: Listen, listen, listen and listen} listen and listen to the FMT. Println ("Hello", listen to WHO)}

4 Compiling and running

Go language compilation consists of two main ways.

4.1 Go Build

Execute go build under the source file directory, and the executable will be generated in the same directory. Compile and run the effect.

4.2 Go Install

Go install will generate executable files under standard path $gopath/bin, which is more suitable for compiling the actual project.

Go install compiles with three prerequisites:

(1) Setting environment variables Gopath

(2) The bin directory of the Golang must be in the environment variable $gopath.
(3) There must be a directory tree containing the SRC, which contains the source code of the local program and the local package, and the upper-level directory of SRC must be in the environment variable $gopath.


We usually set the Gopath in BASHRC

Vim listen to ~/.bashrc# listen to Golangexport listen to gopath=/home/wm/work/basement/golang/programming_in_go/listen to hear the source listen to hear ~/.BASHRC

Compile and run the effect.

This article from "Talking Cabbage" blog, declined reprint!

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.