Home >Backend Development >Golang >Does linux support go language?

Does linux support go language?

青灯夜游
青灯夜游Original
2022-11-25 18:22:122490browse

Linux supports go language because go language can be cross-platform. Due to its modular design and modularity, that is, the code is compiled and converted into the smallest possible binary form, therefore, the Go language does not require dependencies and supports platform independence; its code can be run on any platform (Windows, Linux, Mac OS etc.) and can be compiled on any server and application.

Does linux support go language?

The operating environment of this tutorial: linux7.3 system, GO version 1.18, Dell G3 computer.

Go is a procedural programming language that can be used for fast machine code compilation. It is a statically typed compiled language. It provides a concurrency mechanism that makes it easy to develop multi-core and networked machine-level programs. It is a fast, dynamically typed and interpreted language; it provides support for interfaces and type embedding.

Linux supports go language because go language can be cross-platform.

Go language, like Java language, supports platform independence. Due to its modular design and modularity, i.e. the code is compiled and converted into the smallest possible binary form, therefore, it requires no dependencies. Its code can be compiled on any platform (Windows, Linux, Mac OS, etc.) and can be compiled on any server and application.

No need to use a virtual machine, the Go language code can be directly output as a binary executable file. Moreover, the Go language has its own linker and does not rely on the compiler and linker provided by any system. Therefore, the compiled binary executable file can run in almost any system environment.

Building a Go language development environment on Linux

##1. Install the Go language development package

You can check out the installation package (https://golang.google.cn/dl/) on the Go language official website. The development package has two versions, 32-bit and 64-bit. You need to choose different ones according to the situation of the reader’s computer. version of.

Does linux support go language?

Copy the download link of the Go language development package (https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz). Then, use the cd command in the terminal to enter the directory where you store the installation package (the /usr/local/ directory is used here, readers can also use other directories).

root@ububtu:~# cd /usr/local/
root@ububtu:/usr/local#

Use the wget command to download the Go language development package, as shown below.

root@ububtu:/usr/local# wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
--2019-11-06 10:47:23--  https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz
正在解析主机 dl.google.com (dl.google.com)... 203.208.39.196, 203.208.39.193, 203.208.39.200, ...
正在连接 dl.google.com (dl.google.com)|203.208.39.196|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 120054682 (114M) [application/octet-stream]
正在保存至: “go1.13.4.linux-amd64.tar.gz”

go1.13.4.linux  43%  49.44M  3.56MB/s    剩余 16s         ^go1.13.4.linux 100% 114.49M  4.73MB/s    用时 31s        

2019-11-06 10:47:56 (3.67 MB/s) - 已保存 “go1.13.4.linux-amd64.tar.gz” [120054682/120054682])

Use the tar command to decompress the Go language development package you just downloaded.

root@ububtu:/usr/local# tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz

After successful decompression, a go directory will be added in the current directory. At this point, our Go language development package has been installed. Use the cd command to enter the directory, and then execute the bin/go version command to view it. The current version of the Go language.

root@ububtu:/usr/local/go# bin/go version
go version go1.13.4 linux/amd64

Configuring environment variables

We need to configure 2 environment variables, GOROOT and PATH.

  • The value of GOROOT should be the current installation directory of the Go language:

    export GOROOT=/usr/local/go

  • PATH In order to facilitate the use of Go language commands and Go program executable files, you need to append its value:

    export PATH=$PATH:$GOROOT/bin:$GOBIN

In order to facilitate future use, these environment variables need to be added to the profile file (~/.bash_profile or /etc/profile). If it is used by a single user, the environment variable can be added to the bash_profile file in the home directory. If used by multiple users, it needs to be added to the /etc/profile file. (It is recommended that you set environment variables in the /etc/profile file)

Use the vi /etc/profile command to open the profile file and add the environment variables to the end of the file.

Does linux support go language?

After the addition is completed, use the

:wq command to save and exit.

Then, use the

source /etc/profile command to make the configuration file take effect. Now you can use Go language commands in any directory.

Verify installation

Use the terminal in any directory to execute the

go env command, and the following output will be output to illustrate Go language development The package has been installed successfully.

root@ububtu:~$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/feng/.cache/go-build"
GOENV="/home/feng/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/feng/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
. . .

Tip: Only partial results are shown above.

Related recommendations: "

Linux Video Tutorial"

The above is the detailed content of Does linux support go language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn