如何在Ubuntu中正确安装和配置Go语言。有许多软件包可供选择,但我需要安装哪些包?之后需要配置哪些包才能使用Go软件包,而不存在“无法找到包”错误,例如,其他任何此类基本错误。
我安装了golang
包,但是否需要安装任何其他程序或配置其他组件?
例如,尝试运行以下代码:
package main
import (
"http"
"log"
)
func HelloServer(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Connection", "keep-alive")
w.Write([]byte("hello, world!\n"))
}
func main() {
http.HandleFunc("/", HelloServer)
log.Println("Serving at http://127.0.0.1:8080/")
http.ListenAndServe(":8080", nil)
}
发布于 2014-05-10 18:05:24
安装golang
元文件应该足够了:
sudo apt-get install golang
“这个包是一个元包,安装时保证(大部分)安装了完整的Go开发环境。”因此,在此之后,只需为基本命令键入go help
:
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
在gedit打个招呼。他们的网站中的例子:
package main
import "fmt"
func main() {
fmt.Println("Hello world\n")
}
(将其保存为hello.go)
执行..。
go run hello.go
产量..。
Hello world
#!/usr/bin/gorun
package main
func main() {
println("Hello world!\n")
}
并使其可执行:
chmod +x hello.go
./hello.go
产量..。
Hello world!
(我自己加的\n )
你的例子有一个错误:
导入http
需要是net/http
go run test.go
2014/05/10 20:15:00 Serving at http://127.0.0.1:8080/
https://askubuntu.com/questions/463989
复制相似问题