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

边栏推荐
- Formulaire day05
- Katalon framework test web (XXVI) automatic email
- How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
- Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
- (practice C language every day) pointer sorting problem
- Management and thesis of job management system based on SSM
- Apple submitted the new MAC model to the regulatory database before the spring conference
- vue多级路由嵌套怎么动态缓存组件
- Summary of Chinese remainder theorem
- CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
猜你喜欢

图解网络:什么是热备份路由器协议HSRP?

基于PHP的轻量企业销售管理系统

Session learning diary 1

AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving

mysql数据库的存储

functools下的reduce函数

SQL语句加强练习(MySQL8.0为例)

MySQL one master multiple slaves + linear replication

Leetcode51.n queen

Reduce function under functools
随机推荐
Management and thesis of job management system based on SSM
Katalon框架测试web(二十六)自动发邮件
SQL injection (1) -- determine whether there are SQL injection vulnerabilities
Objective C attribute keyword
vue多级路由嵌套怎么动态缓存组件
SQL語句加强練習(MySQL8.0為例)
Day05 錶格
Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
支持首次触发的 Go Ticker
Support the first triggered go ticker
Typical applications of minimum spanning tree
Is it safe to buy insurance for your children online? Do you want to buy a million dollar medical insurance for your children?
三菱M70宏变量读取三菱M80公共变量采集三菱CNC变量读取采集三菱CNC远程刀补三菱机床在线刀补三菱数控在线测量
Es network layer
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
[database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c
1289_FreeRTOS中vTaskSuspend()接口实现分析
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Objective-C member variable permissions