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

边栏推荐
- Objective-C member variable permissions
- Illustrated network: what is the hot backup router protocol HSRP?
- Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
- Objective C attribute keyword
- If you have just joined a new company, don't be fired because of your mistakes
- (practice C language every day) pointer sorting problem
- Consul of distributed service registration discovery and unified configuration management
- Typical applications of minimum spanning tree
- Solve the problems encountered by the laravel framework using mongodb
- SQL语句加强练习(MySQL8.0为例)
猜你喜欢

Add IDM to Google browser

Redis notes (I) Linux installation process of redis

Katalon framework test web (XXVI) automatic email

Don't disagree, this is the most powerful "language" of the Internet

What kind of experience is it when the Institute earns 20000 yuan a month!

Leetcode51.n queen

如何有效远程办公之我见 | 社区征文
![Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure](/img/ba/c1d40de154344ccc9f2fd1dd4cb12f.png)
Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure

MySQL is dirty

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?
随机推荐
[paddleseg source code reading] paddleseg calculates Miou
Day05 錶格
Es network layer
Mindmanager2022 efficient and easy to use office mind map MindManager
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
pytest多进程/多线程执行测试用例
Package details_ Four access control characters_ Two details of protected
SQL statement strengthening exercise (MySQL 8.0 as an example)
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Katalon框架测试web(二十一)获取元素属性断言
PID of sunflower classic
How to pipe several commands in Go?
【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
What are the virtual machine software? What are their respective functions?
Reduce function under functools
Rhcsa day 2
My opinion on how to effectively telecommute | community essay solicitation
Want to do something in production? Then try these redis commands
[latex] production of complex tables: excel2latex and detail adjustment