https://go.dev/dl/
然后将安装包放在合适的位置,确保路径没有中文。
将下载的二进制包解压至 /usr/local目录
tar -C /usr/local -xzf /mnt/e/ubuntu/go1.17.6.linux-amd64.tar.gz
我们可以查看其内容
# ls /usr/local/go
AUTHORS CONTRIBUTING.md CONTRIBUTORS LICENSE PATENTS README.md SECURITY.md VERSION api bin codereview.cfg doc lib misc pkg src test
配置环境变量
将
export PATH=$PATH:/usr/local/go/bin
添加到~/.bash_profile 或者 /etc/profile
笔者的wsl中没有 ~/.bash_profile,所以添加到 /etc/profile:
使用vim打开,按i进入插入模式,右键粘贴到最后一行,然后:wq保存并退出。如下图所示:
然后执行
source /etc/profile
测试go环境
编写test.go 文件
package main
import "fmt"
func main() {
fmt.Println("test go");
}
测试结果如下所示
$ go run test.go
test go
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)