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.