当前位置:网站首页>【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
2022-07-04 03:52:00 【愚公搬代码】
一、Go语言环境安装
Go语言是一门编译性的语言需要有SDK工具包对其进行编译才能运行,其次需要有一个编辑工具来写代码,最后为SDK中的工具配置环境变量,所以总结一下可以包含三个方面:
- SDK工具包安装
- VSCode安装
- 环境变量配置
Go语言支持的系统有:Linux、FreeBSD、Mac OS X(也称为 Darwin)、Windows。
当将 Go语言源码编写完成此时电脑还不能直接执行,需要使用编译器编译成二进制可执行文件,那么就需要使用Go语言的SDK工具包了。
Go语言SDK安装包下载地址:https://golang.google.cn/dl/

Windows下可以使用 .msi 后缀(在下载列表中可以找到该文件,如go1.18.3.windows-amd64.msi)的安装包来安装。
默认情况下 .msi 文件会安装在 c:\Go 目录下。你可以将 c:\Go\bin 目录添加到Path环境变量中。添加后你需要重启命令窗口才能生效。

输入以下命令测试是否安装成功
go version #输出版本信息
go env #环境信息

二、第一个Go程序
Go语言运行流程图如下:

1.命令行运行
脚本代码test.go如下:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
命令行运行:
go run test.go

编译成exe运行
go build test.go ./test.exe
三、Go语言多版本控制
有时候,我们会遇到用到Go语言的多个版本,为了解决在不同场景下需要安装不同版本的需求,能够方便的进行不同版本间的切换,这里推荐一下gvm。
gvm是Go版本管理器,使用 shell 脚本开发。你可以按照文件进行安装即可,参考: https://github.com/moovweb/gvm 。
安装完成后,我们就可以安装其他go版本了。
gvm install go1.17.6
gvm use go1.17.6
执行完上面的命令之后就可以添加新版本的Go ,GOPATH、GOROOT 等环境变量会自动设置好,然后就可以直接使用指定版本的Go语言了。
总结

边栏推荐
- Pytest multi process / multi thread execution test case
- 程序员远程办公喜忧参半| 社区征文
- leetcode刷题:二叉树08(N叉树的最大深度)
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
- 微信公众号无限回调授权系统源码
- Krypton saikr daily question - CTF
- Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
- 软件测试是干什么的 发现缺陷错误,提高软件的质量
- 仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
- The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
猜你喜欢

2021 RSC | Drug–target affinity prediction using graph neural network and contact maps

微信公众号无限回调授权系统源码

dried food! Generation of rare samples based on GaN

idea修改主体颜色

毕业设计项目

Redis:有序集合zset类型数据操作命令

ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Tcp- simple understanding of three handshakes and four waves
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

架构训练毕业设计+总结
随机推荐
2021 RSC | Drug–target affinity prediction using graph neural network and contact maps
苹果CMS仿西瓜视频大气响应式视频模板源码
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
[microservice openfeign] use openfeign to remotely call the file upload interface
【罗技】m720
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
leetcode刷题:二叉树04(二叉树的层序遍历)
TCP-三次握手和四次挥手简单理解
One click compilation and deployment of MySQL
leetcode刷题:二叉树08(N叉树的最大深度)
Msgraphmailbag - search only driveitems of file types
JS实现文字滚动 跑马灯效果
VIM mapping command
透过JVM-SANDBOX源码,了解字节码增强技术原理
Restore the subtlety of window position
Flink学习6:编程模型
Tcp- simple understanding of three handshakes and four waves
[microservice openfeign] @feignclient detailed explanation
RHCSA 06 - suid, sgid, sticky bit(待补充)
01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)