赞
踩
首先是安装GO语言包,预备要安装的是go version go1.22.4 linux/amd64,
移步至https://golang.google.cn/dl/ ,选择go1.22.4.linux-amd64.tar.gz 下载
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz
(You may need to run the command as root or through sudo).
Do not untar the archive into an existing /usr/local/go tree. This is known to produce broken Go installations.
export PATH=$PATH:/usr/local/go/bin
Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.
$ go version
Confirm that the command prints the installed version of Go.
mkdir hello
cd hello
$ go mod init example/hello
go: creating new go.mod: module example/hello
在实际开发中,模块路径通常是存储库 源代码的保存位置。例如,模块路径可能是 。如果您计划发布 您的模块供其他人使用,模块路径必须是 Go 工具可以从中下载模块的位置。有关的更多信息 使用模块路径命名模块,请参阅管理依赖项
hello.go
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
$ go run .
Hello, World!
go run 命令是用于完成工作的众多命令之一。使用以下命令获取其他命令的列表:
$ go help
You can use the pkg.go.dev site to find published modules whose packages have functions you can use in your own code. Packages are published in modules – like – where others can use them. Modules are improved with new versions over time, and you can upgrade your code to use the improved versions. rsc.io/quote
package main
import "fmt"
import "rsc.io/quote"
func main() {
fmt.Println(quote.Go())
}
cps@linx:~/hello$ go mod tidy
go: finding module for package rsc.io/quote
go: found rsc.io/quote in rsc.io/quote v1.5.2
$ go run .
Don’t communicate by sharing memory, share memory by communicating.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。