Debian与Golang的兼容性非常好。以下是关于在Debian系统上安装和使用Golang的详细信息:
使用官方仓库安装:
sudo apt update
sudo apt install golang
。使用这种方法可以从Debian的官方软件仓库中安装Go语言。但是,大多数情况下,官方仓库中的软件包可能不是最新版本。如果你需要最新版本的Go,你可能需要考虑手动下载安装。
从官方网站手动下载并安装:
.tar.gz
文件。wget
下载你选择的版本。/usr/local
:sudo tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz
。~/.profile
或~/.bashrc
文件,添加以下内容:export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source ~/.profile
或source ~/.bashrc
。go version
。。server.go
,并添加以下代码:package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, you've requested: %s
“, r.URL.Path)
})
http.ListenAndServe(”:8080", nil)
}
```
2. 编译Go文件:go build server.go
。
3. 创建并启动一个新的systemd服务来运行Go服务器。。
CGO_ENABLED=0
进行编译:CGO_ENABLED=0 go build -o server server.go
。cmd/link
进行外部链接:go build -o server -ldflags '-linkmode "external" -extldflags "-static"' server.go
。。总的来说,无论是从官方仓库还是从官方网站手动下载安装包,Debian都能提供对Golang的良好支持。用户可以根据自己的需要选择合适的安装方式。同时,Golang在Debian上的运行也非常稳定,可以满足各种开发需求。