Focus on cloud service provider activities
Notes on website operation and maintenance

Record the compilation and installation of GO language environment in the Ubuntu image system

Some of our scripts and environments need to be able to execute GO language in the server, but the default WEB environment does not support it. Go is a compiled static type programming language developed by Google. At present, we see that many applications are written in Go, such as Docker, Kubernetes and Caddy.

In this article, Lao Zuo's Notes Record how to see the Go language environment in my commonly used Ubuntu image system. If we need it, we can use it as a reference. Of course, if we have a better method, we can choose to install it by ourselves. For example, some scripts can be installed by one click.

Before installing, we can use curl to download the current binary file of Go from the official download page. Check whether the download page is updated, and replace 1.12.9 with the latest stable version if necessary.

curl -O https://storage.googleapis.com/golang/go1.12.9.linux-amd64.tar.gz

Then we can verify:

sha256sum go1.12.9.linux-amd64.tar.gz

Unzip and adjust the directory:

tar -xvf go1.12.9.linux-amd64.tar.gz

sudo chown -R root:root ./go

sudo mv go /usr/local

Then we need to adjust the path variable.

Edit file:

~/.profile

Here we can use the vi editor.

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

Save the file, and then load the command into the current shell instance.

source ~/.profile

Then we will start to check whether the installation is successful. We can create a folder named go in the current directory, which I use to test. Of course, you can also create your own familiar directory.

mkdir -p go/src/hello && cd go/src/hello
touch hello.go

Create a hello.go file.

package main

import "fmt"

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

Drop the test script. Then compile and execute

go build

./hello

If we can see hello and world, it is no problem.

In this way, we can install GO language support in our Ubuntu image through a few simple steps.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Record the compilation and installation of GO language environment in the Ubuntu image system


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge