当前位置:网站首页>【愚公系列】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.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
- Tcp- simple understanding of three handshakes and four waves
- (pointer) write a function to compare the size of strings by yourself, which is similar to StrCmp.
- Redis:集合Set类型数据的操作命令
- I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer
- Rhcsa-- day one
- idea修改主体颜色
- Unity draws the trajectory of pinball and billiards
- leetcode刷题:二叉树04(二叉树的层序遍历)
- 干货!基于GAN的稀有样本生成
猜你喜欢

LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDebug”(main.obj 中)

Graduation project: design seckill e-commerce system

leetcode刷题:二叉树05(翻转二叉树)

96% of the collected traffic is prevented by bubble mart of cloud hosting

02 ls 命令的具体实现

The maximum expiration time of client secret in azure ad application registration is modified to 2 years

Rhcsa-- day one

Perf simple process for multithreaded profile

DP83848+网线热拔插

仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
随机推荐
[microservice openfeign] @feignclient detailed explanation
Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)
Redis:有序集合zset类型数据操作命令
Leetcode brush question: binary tree 06 (symmetric binary tree)
There is a problem that the package cannot be parsed in the like project
02 specific implementation of LS command
Apple CMS imitation watermelon video atmospheric response video template source code
(pointer) write a function to compare the size of strings by yourself, which is similar to StrCmp.
【webrtc】m98 ninja 构建和编译指令
Lnk2038 detected a mismatch of "runtimelibrary": the value "md_dynamicrelease" does not match the value "mdd_dynamicdebug" (in main.obj)
Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
Modstartblog modern personal blog system v5.2.0 source code download
JS实现文字滚动 跑马灯效果
LevelDB源码解读-SkipList
Flink learning 6: programming model
如何远程办公更有效率 | 社区征文
Unity 绘制弹球和台球的运动轨迹
Emlog用户注册插件 价值80元
C language bidirectional linked list first edition
dried food! Generation of rare samples based on GaN