当前位置:网站首页>【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
【愚公系列】2022年7月 Go教学课程 002-Go语言环境安装
2022-07-04 03:46: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 mainimport "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.6gvm use go1.17.6
执行完上面的命令之后就可以添加新版本的Go ,GOPATH、GOROOT 等环境变量会自动设置好,然后就可以直接使用指定版本的Go语言了。
总结
边栏推荐
- Jenkins configures IP address access
- How much does it cost to open a futures account in China? Where is it safe to open an account at present?
- Teach you how to optimize SQL
- [PaddleSeg 源码阅读] PaddleSeg计算Dice
- Management and thesis of job management system based on SSM
- Katalon框架测试web(二十六)自动发邮件
- Handler source code analysis
- Add token validation in swagger
- Epidemic strikes -- Thinking about telecommuting | community essay solicitation
- warning: LF will be replaced by CRLF in XXXXXX
猜你喜欢
Katalon框架测试web(二十六)自动发邮件
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
Webhook triggers Jenkins for sonar detection
Mindmanager2022 efficient and easy to use office mind map MindManager
mysql数据库的存储
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
Pytest multi process / multi thread execution test case
用于TCP协议交互的TCPClientDemo
MySQL maxscale realizes read-write separation
随机推荐
Objective-C description method and type method
1289_ Implementation analysis of vtask suspend() interface in FreeRTOS
Objective-C member variable permissions
Handler source code analysis
Epidemic strikes -- Thinking about telecommuting | community essay solicitation
Recursive structure
选择排序与冒泡排序模板
Summary of Chinese remainder theorem
Objective-C string class, array class
Sword finger offer:55 - I. depth of binary tree
Support the first triggered go ticker
@Scheduled scheduled tasks
深入浅出对话系统——使用Transformer进行文本分类
新型数据中心,助力加快构建以数据为关键要素的数字经济
EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
pytest多进程/多线程执行测试用例
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
MySQL query
Introduction to asynchronous task capability of function calculation - task trigger de duplication
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush