Get the App
SLTechnology News&Howtos  ›  Development  › 

How to install Golang under Linux

Shulou Source: shulou.com Published: 2022-06-01 18:09:07 09月18日 Update

This article introduces the knowledge of "how to install Golang under Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Go (also known as Golang) is a static strongly typed and compiled language developed by Robert Griesemer,Rob Pike and Ken Thompson of Google. The syntax of Go is similar to that of C, but its functions are: memory security, GC (garbage collection), structure and CSP-style concurrent computing.

1. Install Golang

* * system environment used in this article: * * CentOS Linux release 8.0.1905 (Core)

Execute the following command in turn: download the installation package and extract it to the / usr/local directory

[root@192 ~] # wget https://studygolang.com/dl/golang/go1.15.2.linux-amd64.tar.gz[root@192 ~] # tar-zxvf go1.15.2.linux-amd64.tar.gz-C / usr/local/

If you want to download another version, you can download it from the Chinese official website.

two。 Configure the environment

(1) to execute an order:

[root@192 ~] # vim .bash _ profile

(2) add the following:

Export GOROOT=/usr/local/go # Golong installation directory export GOPATH=$HOME/goProject # future working directory export PATH=$PATH:$GOROOT/bin:$GOPATH/bin # add $GOROOT and $GOPATH to PATH to facilitate setting up agents using export GOPROXY= https://goproxy.io #

(3) execute the order:

[root@192 ~] # source .bash _ profile [root @ 192 ~] # go versiongo version go1.15.2 linux/amd64

Executing go version displays the version information indicating that the installation was successful.

3. Create a working directory [root@192 ~] # mkdir-p goProject/ {src,pkg,bin}

Where:

Src: contains Golang source files; pkg: contains package objects and compiled library files; bin: contains executable commands; 4. Write the first Golang program

(1) under the ~ / goProject/src/ directory, vim HelloWorld.go, copy the following content in, save and exit

Package mainimport ("fmt") func main () {fmt.Println ("Hello World!")}

(2) execute go run HelloWorld.go, as follows:

[root@192 src] # go run HelloWorld.goHello World! [root@192 src] # "how to install Golang under Linux" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Catalog content command more environment knowledge language work compilation utility security success proximity success and then information memory function also known as dilemma Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information Redmi NVidia Microsoft