Gopher into the pit one, go language installation and the first program

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

1. Download

Download Address: https://golang.org/dl/, support LINUX,WINDOWS,MAC,FREEBSD operating system and 32-bit (386) and 64-bit (AMD64) X86 processor architectures. Select your system environment corresponding to the download is OK. (The following is described in the Ubuntu 16.4 32-bit system environment).

Tips: Be sure to download the corresponding version, or there will be a problem, I started to download is the 64-bit version, under 32-bit operation has been error, as follows:

root@ubuntu:/usr/local/go/src# go run index.go bash: /usr/local/go/bin/go: cannot execute binary file: 可执行文件格式错误

2. Installation

Download the corresponding installation package, then execute the following code to extract the files to /usr/local the Go official recommendation directory.

tar -C /usr/local -xzf go1.8.3.linux-386.tar.gz

Replace the previous part of the above code with your own installation package file name, so your program directory is /usr/local/go , enter the directory, LS, can see a lot of folders and files:

    • API folder . Used to store variables, constants, functions, and so on in each version of Go.
    • Bin folder . Used to store the main standard command files, including go, Godoc, etc.
    • Blog Folder . Articles for storing official blogs.
    • Doc folder . For hosting a local official website, we can run it by name and godoc -http=:8222 then enter 127.0.0.1:8222 in the browser to view it.
    • Lib folder . A library file for storing features.
    • Misc Folder . Instructions and tools for storing some of the auxiliary classes.
    • pkg folder . Used to store all archive files after installing the Go standard library.
    • src folder . Used to store all the source files.
    • Test Folder . For storing tests and verifying the files associated with the go itself.

Next, we need to set an environment variable for go. To /usr/local/go/bin add to the PATH environment variable, you need to add this line to your /etc/profile (System-wide permanent installation).

export PATH=$PATH:/usr/local/go/bin

3, the first go version of the Hello World program.

Enter the/USR/LOCAL/GO/SRC directory, create a file named Index.go, and enter the following code:

package mainimport "fmt"func main() {    fmt.Printf("hello, world\n")}

Run it through go.

root@ubuntu:/mnt/hgfs/www/golang# go run hello.go hello, world

If the output of the success, then, congratulations.

Related Article

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.