go环境安装配置全解-深入理解

背景

        换了个新电脑,之前配置好的各种开发环境全部没了,又得重新配置一遍,不过最紧急要配置的就是代码开发环境。之前一直用的go语言,所以得配置go相关的环境,上一次配置纯纯copy网上配置,也没有去深入了解每一个配置到底是什么含义,结果在以同样方式配置好开发机环境后,有个依赖包始终拉不到,找一个资深大佬看,贴了配置项,结果被问住了,不知道里面配置的goproxy的值是啥含义。。。一时比较尴尬,因此重新学习一遍go环境配置中的每一项配置

配置操作

主要还是针对mac的配置,如果是windows系统,基本配置项是一样的,只是配置的位置不一样,因此不单独说

安装go sdk

        第一步当然是安装go的sdk,从官网上下载go版本,解压就完事了,官网有很详细的说明啦,不过还是copy一下,详细(翻译)说明一下

Download and install - The Go Programming Language (google.cn)

mac

1. Open the package file you downloaded and follow the prompts to install Go.

The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

(打开下载的安装,按照提示去安装go,既然是按照提示去安装go环境,就不说了,记得按照2和3说的验证,安装好后,执行go version查看安装的go版本是不是下载的版本)

2. Verify that you've installed Go by opening a command prompt and typing the following command:

$ go version

3. Confirm that the command prints the installed version of Go.

linux

(稍微复杂,多讲几句,有一个环节没有操作可能就安装不生效)

1. Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:

$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz

(You may need to run the command as root or through sudo).

(前提是首先删除掉曾经已经安装过的go安装包,使用管理员权限删除原本的目录 rm -rf /usr/local/go)

(在完全删除后,执行已下载go压缩包的解压,tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz)

Do not untar the archive into an existing /usr/local/go tree. This is known to produce broken Go installations.

2. Add /usr/local/go/bin to the PATH environment variable.

You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

export PATH=$PATH:/usr/local/go/bin

(添加go的可执行命令到环境变量,可以在 $HOME/.profile or /etc/profile 这两个文件里面添加这个命令行export PATH=$PATH:/usr/local/go/bin,当然如果使用了别的终端,比如zsh,则在./zshrc文件中添加这个命令也可;下面的note说的很

  • 19
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值