In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to install the Go environment for Linux. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Go (also known as Golang) is an open source programming language that makes it easy to build simple, reliable, and efficient software. 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.
Specific methods for installing Go environment in Linux
Install Go environment Golang official website download address: https://golang.org/dl/
Open the download address on the official website and select the corresponding system version, and copy the download link. Here I choose go1.11.5.linux-amd64.tar.gz: https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz.
Image.png
Cd goes to the directory you use to store the installation package. I'm used to creating a go folder under ~.
# create a go folder under ~ and enter the go folder mkdir ~ / go & & cd ~ / go to download the go package wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz downloaded.
Extract the tar to the / usr/loacl directory (officially recommended) to get the go folder, etc.
Tar-C / usr/local-zxvf go1.11.5.linux-amd64.tar.gz add the / usr/loacl/go/bin directory to the PATH variable. Add to / etc/profile or $HOME/.profile
# accustomed to using vim, if not, you can use the command `sudo apt-get install vim` to install a vim / etc/profile # add export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin on the last line # save and exit after source (the usage of vim can be searched by yourself) source / etc/profile execution
Go version, if the actual version number, the Go environment is installed successfully. Isn't it easy?
Run the first program to create your workspace (Workspaces), the official recommended directory $HOME/go.
Mkdir $HOME/go declares your workspace path to the environment variable. Similar to step 5 in the previous section.
# Edit ~ / .bash_profile file vim ~ / .bash_profile # add the following sentence on the last line. HOME/go is the path to your workspace, or you can change it to your favorite path export GOPATH=$HOME/go # after saving and exiting, source (you can search for the usage of vim) source ~ /. Bash_profile create your first project directory in your workspace
# create and enter your first project directory mkdir-p $GOPATH/src/hello & & cd $GOPATH/src/hello to create a file named hello.go in your project directory
Vim hello.go pastes the following into the hello.go file
Package main import "fmt" func main () {fmt.Printf ("hello, world\ n")} is ready, the project directory and project files are ready. Now let's go to our project directory ($GOPATH/src/hello) to build our project.
# if your current directory is not in $GOPATH/src/hello, you need to execute "cd $GOPATH/src/hello" to enter the directory # execute the go build command to build the project for a while. After the command is executed, you can see that there will be an extra hello file in the directory. This is the file we compiled. How to execute our program? Just execute. / xxx in the current directory! Are you pounding chicken and eggs?
. / hello
Some introduction to Go the environment variable: $GOROOT: indicates the directory where Go is installed. This is the go folder in the folder we unzipped above.
$GOPATH: represents our workspace. The place where our project catalogue is kept.
GOPATH directory: generally speaking, there are three folders under GOPATH: bin, pkg, and src. If not, create your own. Each folder has its own function.
Bin: the path where the compiled executable files can be stored
Pkg: the path to the generated .a file when compiling the package
Src: source code path. Generally, our project is created under src.
Note: if you want to use Go Mod (Go1.11 and above support) for package management, you need to create a project in a directory other than GOPATH.
On how to install Linux Go environment to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.