Go Language Environment Installation
Go language supports the following systems:
- Linux
- FreeBSD
- Mac OS X (also known as Darwin)
- Windows
The installation package download address is: https://golang.org/dl/.
If you cannot access the above link, you can use this address: https://golang.google.cn/dl/.
The package names corresponding to each system are:
Operating System | Package Name |
---|---|
Windows | go1.4.windows-amd64.msi |
Linux | go1.4.linux-amd64.tar.gz |
Mac | go1.4.darwin-amd64-osx10.8.pkg |
FreeBSD | go1.4.freebsd-amd64.tar.gz |
UNIX/Linux/Mac OS X, and FreeBSD Installation
The following describes the installation method using source code on UNIX/Linux/Mac OS X, and FreeBSD systems:
- Download the binary package: go1.4.linux-amd64.tar.gz.
Extract the downloaded binary package to the /usr/local directory.
tar -C /usr/local -xzf go1.4.linux-amd64.tar.gz
Add the /usr/local/go/bin directory to the PATH environment variable:
export PATH=$PATH:/usr/local/go/bin
The above method only temporarily adds PATH, and it will be lost after closing the terminal.
You can edit ~/.bash_profile or /etc/profile and add the following command to the end of the file for a permanent effect:
export PATH=$PATH:/usr/local/go/bin
After adding, you need to execute:
source ~/.bash_profile
or
source /etc/profile
Note: On Mac systems, you can use the .pkg installation package to complete the installation by double-clicking, and the installation directory is /usr/local/go/.
Windows System Installation
On Windows, you can use the .msi suffix (found in the download list, such as go1.4.2.windows-amd64.msi) installation package to install.
By default, the .msi file will install in the c:\Go directory. You can add the c:\Go\bin directory to the Path environment variable. You need to restart the command window for the changes to take effect.
Installation Test
Create a working directory C:>Go_WorkSpace.
test.go file code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
Execute the above code using the go command, and the output is as follows:
C:\Go_WorkSpace>go run test.go
Hello, World!