Home  >  Article  >  Operation and Maintenance  >  Linux does not support go language

Linux does not support go language

王林
王林forward
2023-05-29 22:25:361753browse

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.

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. It requires no dependencies due to its modular design and the compilation and conversion of code into a minimized binary form. Its code can be compiled on any platform (Windows, Linux, Mac OS, etc.) and can be compiled on any server and application.

Go language code can be directly compiled into binary executable files without using a virtual machine. The Go language has an independent linker and does not need to rely on the compiler and linker provided by any operating 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 view it on the Go language official website Looking at the installation package, the development package has two versions: 32-bit and 64-bit. You need to choose different versions according to the situation of the reader's computer.

Linux does not support go language

Copy the download link of the Go language development package. 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.

<pre class="brush:js;toolbar:false">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])</pre><p>Use the tar command to decompress the Go language development package you just downloaded. </p><pre class="brush:js;toolbar:false">root@ububtu:/usr/local# tar -C /usr/local -xzf go1.13.4.linux-amd64.tar.gz</pre><p>After successful decompression, a go directory will be added in the current directory. At this point, our Go language development kit has been installed. Use the cd command to enter the directory, and then execute bin/ You can use the go version command to view the current Go language version. </p><pre class="brush:js;toolbar:false">root@ububtu:/usr/local/go# bin/go version go version go1.13.4 linux/amd64</pre><p><strong>Configure environment variables</strong></p> <p>We need to configure 2 environment variables, GOROOT and PATH. </p> <ul class=" list-paddingleft-2"> <li><p>The value of GOROOT should be the current installation directory of the Go language: <code>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 to 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.

    Linux does not 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. The following output shows that the Go language development package has been successfully installed.

    <pre class="brush:js;toolbar:false">root@ububtu:~$ go env GO111MODULE=&quot;&quot; GOARCH=&quot;amd64&quot; GOBIN=&quot;&quot; GOCACHE=&quot;/home/feng/.cache/go-build&quot; GOENV=&quot;/home/feng/.config/go/env&quot; GOEXE=&quot;&quot; GOFLAGS=&quot;&quot; GOHOSTARCH=&quot;amd64&quot; GOHOSTOS=&quot;linux&quot; GONOPROXY=&quot;&quot; GONOSUMDB=&quot;&quot; GOOS=&quot;linux&quot; GOPATH=&quot;/home/feng/go&quot; GOPRIVATE=&quot;&quot; GOPROXY=&quot;https://proxy.golang.org,direct&quot; GOROOT=&quot;/usr/local/go&quot; GOSUMDB=&quot;sum.golang.org&quot; GOTMPDIR=&quot;&quot; . . .</pre><p> Tip: Only partial results are shown above. <br></p>

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

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete