Install Go locale on Ubuntu16
Version Information###
Operating system: Ubuntu 16.04.5 LTS (Server version, 64-bit)
Go version: 1.11
installation###
- Download the Go installation package, address: https://dl.google.com/go/go1.11.linux-amd64.tar.gz
- Copy the downloaded go1.11.linux-amd64.tar.gz file to Ubuntu's /usr/local directory, execute the decompression command tar -zxvf go1.11.linux-amd64.tar.gz, and find /usr/local There is a go directory under the directory, which is the decompressed folder;
- Support global commands: open the /etc/profile file with vi, add a line at the end, the content is export PATH=$PATH:/usr/local/go/bin;
- Make the configuration effective: source /etc/profile;
- Enter go version verification, you can see the content go version go1.11 linux/amd64, the installation is successful;
Set up workspace###
The go environment has been installed, and we will create multiple go application projects in the future. If these projects are only placed in the /usr/local/go directory, it is obviously inappropriate. How can they be placed in other directories and still compile normally? Run it? This is to set up the workspace, which is the GOPATH environment variable;
- Create the folder /usr/local/go_workspace, we use this folder as the workspace;
- Open the ~/.bash_profile file with vi and add a line at the end with the content export GOPATH=/usr/local/go_workspace;
- Make the global command effective: source ~/.bash_profile;
verification###
- Create the folder /usr/local/go_workspace/src/hello/;
- Create a hello.go file in the /usr/local/go_workspace/src/hello/ directory with the following content:
package main
import"fmt"
func main(){
fmt.Printf("hello, world\n")}
- Verify direct operation: In the /usr/local/go_workspace/src/hello/ directory, execute the command go run hello.go, you can successfully execute:
root@docker:/usr/local/go_workspace/src/hello# go run hello.go
hello, world
- Verify the compilation and build: In the /usr/local/go_workspace/src/hello/ directory, execute the command go build, after the execution, there is an additional hello file in the current directory, as shown in the red box in the following figure:
Running this file has the same effect as go run hello.go;
- Verify install: In the /usr/local/go_workspace/src/hello/ directory, execute the command go install. After execution, there is an additional bin folder in the /usr/local/go_workspace/ directory, and there is a hello file in it, as shown in the figure below Show:
Running this file has the same effect as go run hello.go;
At this point, the Go language environment is set up under the Ubuntu16 environment, let's experience this popular language together!