1,官网:
https://golang.google.cn/
2,下载页面:
https://golang.google.cn/dl/
我们选择linux版本下载,复制地址
3,用wget下载到本地:
root@lhdpcg:~# mkdir /usr/local/source root@lhdpcg:~# mkdir /usr/local/soft root@lhdpcg:~# cd /usr/local/source root@lhdpcg:/usr/local/source# mkdir go root@lhdpcg:/usr/local/source# cd go root@lhdpcg:/usr/local/source/go# wget https://go.dev/dl/go1.17.6.linux-amd64.tar.gz
说明:刘宏缔的go森林是一个专注golang的博客,
地址:https://blog.csdn.net/weixin_43881017
说明:作者:刘宏缔 邮箱: 371125307@qq.com
1,解压:
root@lhdpcg:/usr/local/source/go# tar -zxvf go1.17.6.linux-amd64.tar.gz
2,移动到安装目录下
root@lhdpcg:/usr/local/source/go# mv go/ /usr/local/soft/
1,编辑profile
root@lhdpcg:/usr/local/source/go# vim /etc/profile
添加两行:
export GOROOT=/usr/local/soft/go export PATH=$PATH:$GOROOT/bin
2,使profile生效
root@lhdpcg:/usr/local/source/go# source /etc/profile
3,查看go的版本
root@lhdpcg:/usr/local/source/go# go version go version go1.17.6 linux/amd64
root@lhdpcg:~# mkdir /data/ root@lhdpcg:~# mkdir /data/goapp root@lhdpcg:~# mkdir /data/goapp/hello root@lhdpcg:~# cd /data/goapp/hello root@lhdpcg:/data/goapp/hello# vim hello.go
代码:
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
运行:
root@lhdpcg:/data/goapp/hello# go mod init hello go: creating new go.mod: module hello go: to add module requirements and sums: go mod tidy root@lhdpcg:/data/goapp/hello# go build root@lhdpcg:/data/goapp/hello# ./hello hello, world
root@lhdpcg:/data/goapp/hello# more /etc/os-release PRETTY_NAME="Ubuntu 21.10" NAME="Ubuntu" VERSION_ID="21.10" VERSION="21.10 (Impish Indri)" VERSION_CODENAME=impish ID=ubuntu ID_LIKE=debian HOME_URL="Enterprise Open Source and Linux | Ubuntu" SUPPORT_URL="Official Ubuntu Documentation" BUG_REPORT_URL="Bugs : Ubuntu" PRIVACY_POLICY_URL="Data privacy | Ubuntu" UBUNTU_CODENAME=impish