当前位置:网站首页>【愚公系列】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语言了。
总结

边栏推荐
- I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
- Flink学习8:数据的一致性
- 01 QEMU starts the compiled image vfs: unable to mount root FS on unknown block (0,0)
- Krypton saikr daily question - CTF
- hbuildx中夜神模拟器的配置以及热更新
- I.MX6U-ALPHA开发板(C语言版本LED驱动实验)
- C language bidirectional linked list first edition
- RHCSA 01 - 创建分区与文件系统
- Idea configuration 360zip open by default -- external tools
- Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)
猜你喜欢

Idea configuration 360zip open by default -- external tools

普源DS1000Z系列数字示波器在通信原理实验中的应用方案

ModStartBlog 现代化个人博客系统 v5.2.0 源码下载

leetcode刷题:二叉树04(二叉树的层序遍历)

What does software testing do? Find defects and improve the quality of software

Flink学习6:编程模型

Flink learning 8: data consistency

Unity draws the trajectory of pinball and billiards

I Build a simple microservice project

Redis:有序集合zset类型数据操作命令
随机推荐
Apple CMS imitation watermelon video atmospheric response video template source code
I Build a simple microservice project
RHCSA 08 - automount配置
LevelDB源码解读-SkipList
Small record of thinking
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Two commonly used graphics can easily realize data display
Unity资源路径
Leetcode brush question: binary tree 06 (symmetric binary tree)
Asynchronous development process - touch your hand and lead you to realize a promise
Flink学习8:数据的一致性
网络 - VXLAN
Configuration and hot update of nocturnal simulator in hbuildx
程序员远程办公喜忧参半| 社区征文
Leader: who uses redis expired monitoring to close orders and get out of here!
干货!基于GAN的稀有样本生成
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
How to add custom API objects in kubernetes (1)
tdk-lambda电源主要应用
LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)