https://studygolang.com/dl 网址下载
cd /home/soft
wget https://studygolang.com/dl/golang/go1.15.7.linux-amd64.tar.gz
tar -xvf go1.15.7.linux-amd64.tar.gz 解压
mv /home/soft/go /usr/local/go
[root@localhost soft]# cd /usr/local/go
[root@localhost go]# ll
total 216
drwxr-xr-x. 2 root root 4096 Jan 20 04:04 api
-rw-r--r--. 1 root root 55669 Jan 20 04:01 AUTHORS
drwxr-xr-x. 2 root root 29 Jan 20 04:11 bin
-rw-r--r--. 1 root root 1339 Jan 20 04:01 CONTRIBUTING.md
-rw-r--r--. 1 root root 95475 Jan 20 04:01 CONTRIBUTORS
drwxr-xr-x. 7 root root 4096 Jan 20 04:04 doc
-rw-r--r--. 1 root root 5686 Jan 20 04:01 favicon.ico
drwxr-xr-x. 3 root root 18 Jan 20 04:04 lib
-rw-r--r--. 1 root root 1479 Jan 20 04:01 LICENSE
drwxr-xr-x. 12 root root 165 Jan 20 04:04 misc
-rw-r--r--. 1 root root 1303 Jan 20 04:01 PATENTS
drwxr-xr-x. 6 root root 76 Jan 20 04:12 pkg
-rw-r--r--. 1 root root 1607 Jan 20 04:01 README.md
-rw-r--r--. 1 root root 26 Jan 20 04:01 robots.txt
-rw-r--r--. 1 root root 397 Jan 20 04:01 SECURITY.md
drwxr-xr-x. 47 root root 4096 Jan 20 04:09 src
drwxr-xr-x. 23 root root 12288 Jan 20 04:09 test
-rw-r--r--. 1 root root 8 Jan 20 04:09 VERSION
[root@localhost go]#
vim /etc/profile
export GOPATH=/home/wfs/server #代码路径,新编写的项目代码所在目录
export GOROOT=/usr/local/go #安装路径
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source /etc/profile #让环境变量生效
[root@localhost server]# pwd
/home/wfs/server
[root@localhost server]# ll
total 20
-rwxr-xr-x. 1 root root 219 Feb 1 15:58 build_lite.sh
-rw-r--r--. 1 root root 83 Feb 1 16:32 main.go
-rw-r--r--. 1 root root 5508 Feb 1 15:58 wfs_server_lite.go
-rw-r--r--. 1 root root 1349 Feb 1 15:58 wfs_websockets_hub.go
[root@localhost server]#
main.go文件如下
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
[root@localhost server]# go run ./main.go
Hello, World!
[root@localhost server]#
生效成功
另外,如果要加载模块,示例如下:
go get github.com/gorilla/websocket