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

边栏推荐
- Defensive programming skills
- Third party login initial version
- “软硬皆施”,助力建成新型云计算数据中心
- warning: LF will be replaced by CRLF in XXXXXX
- SQL語句加强練習(MySQL8.0為例)
- 函数计算异步任务能力介绍 - 任务触发去重
- 2022-07-03:数组里有0和1,一定要翻转一个区间,翻转:0变1,1变0。 请问翻转后可以使得1的个数最多是多少? 来自小红书。3.13笔试。
- Day05 錶格
- Recent learning fragmentation (14)
- Objective-C member variable permissions
猜你喜欢

JVM family -- heap analysis

Jenkins configures IP address access

Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡

Go 语言入门很简单:Go 实现凯撒密码

Add token validation in swagger

What kind of experience is it when the Institute earns 20000 yuan a month!
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类

pytest多进程/多线程执行测试用例

How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!

Penetration practice - sqlserver empowerment
随机推荐
Audio and video technology development weekly | 232
pytest多进程/多线程执行测试用例
Simple dialogue system -- text classification using transformer
super_ Subclass object memory structure_ Inheritance tree traceability
CSP drawing
pytest多进程/多线程执行测试用例
JVM family -- monitoring tools
Formulaire day05
The property of judging odd or even numbers about XOR.
Detailed explanation of PPTC self recovery fuse
New year's first race, submit bug reward more!
system information
Webhook triggers Jenkins for sonar detection
Consul of distributed service registration discovery and unified configuration management
[paddleseg source code reading] normalize operation of paddleseg transform
Webhook triggers Jenkins for sonar detection
Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
Zlmediakit compilation and webrtc push-pull flow testing
JDBC 进阶