Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Golang under Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report