Directory:
- Preface
- First Installation Method: Download the Binary Package
- 1. Download [Go Binary Package] [2].
- 2. Configuration:
- 3. Detection:
- Method 2: Use the gvm plug-in
- 1. Install the [gvm] [3] plug-in:
- 2. Install [go] [1] through [gvm] [3]:
- 3. Detection:
- Classic example:
- 1. Code
- 2. Run
Preface
I recently learned the Go language and recorded some processes. The first step is to install the Go environment.
First Installation Method: Download the Binary Package 1. Download the [Go Binary Package] [2].
# Pay Attention to the corresponding operating system and CPU architecture when downloading. aria2c 'https: // go.googlecode.com/files/go1.1.linux-386.tar.gz'unzip decompress tar zxvf go1.1.linux-386.tar.gz go
2. Configuration:
# Echo "export GOROOT = $ HOME/GO">. zshrc # GO third-party package installation path or project path echo "export GOPATH = $ HOME/workspace/go">. zshrc # Add PATHecho "export PATH = $ GOROOT/bin: $ GOPATH/bin: $ PATH" >>>. zshrc
3. Detection:
# Check whether go is available which go # view go version # view go environment variable go env
Method 2: Use the gvm plug-in. 1. Install the [gvm] [3] plug-in:
# Install bash <(curl-s https://raw.github.com/moovweb/gvm/master/binscripts/gvm-installer) # configure echo '[[-s "$ HOME /. gvm/scripts/gvm "] & source" $ HOME /. gvm/scripts/gvm "] '>. zshrc source. zshrc # gvm version Detection
2. Install [go] [1] through [gvm] [3]:
# List all supported versions of gvm listall # download the source code, compile and install go1.1gvm install go1.1 # list the installed gvm list # Use go1.1, which can be set as the default value (add the -- default parameter) gvm use go1.1 [-- default]
3. Detection:
See detection in the first method.
For more information, visit the official gvm website.
Classic example: 1. Code
# Hello. gopackage mainimport ("fmt") func main () {fmt. Printlf ("Hello, world! ")}
2. Run
# Run go run hello. go # compile and run go build hello. go./hello