golang 安装

释放双眼,带上耳机,听听看~!

安装

多版本管理

  • 通过下面的脚本可以快速安装和管理多个golang版本

  • 需要在/usr/local目录下创建go-dir和go-tar两个目录

    • 如果在Linux系统下需要吧darwin改成linux


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1BigVersion=$1
2SmallVersion=$2
3
4RootPath=/usr/local
5DirPath=/usr/local/go-dir/go-${BigVersion}-${SmallVersion}
6TarFile=go1.${BigVersion}.${SmallVersion}.darwin-amd64.tar.gz
7
8wget  https://golang.google.cn/dl/${TarFile}
9mkdir -p ${DirPath}
10tar -C ${DirPath} -xzf ${TarFile}
11cd ${RootPath}; rm go
12ln -s ${DirPath}/go/ ${RootPath}/go
13
14

配置环境变量

golang 安装

  • GO111MODULE作为gomod的开关

  • 默认为auto模式,即存在go.mod文件的目录开启module模式

  • GOPROXY可以添加代理

  • 需要版本1.13及以上

    • 以英文逗号 “,” 分割的 Go 模块代理列表,允许设置多个模块代理
  • GOPRIVATE可以设定组织内的私有库

  • 可以通过.profile文件设置


1
2
3
4
5
6
7
8
1# vim ~/.profile
2export GOPROXY="https://goproxy.cn,direct"
3export GOPRIVATE="*.xxx.org"
4export GOSUMDB="golang.google.cn"
5
6# source ~/.profile
7
8
  • 也可以通过go env -w设置


1
2
3
4
5
1go env -w GOPROXY="https://goproxy.cn,direct"
2go env -w GOPRIVATE="*.xxx.org"
3go env -w GO111MODULE=on
4
5
  • /etc/profile文件对整个计算机生效

  • ~/.profile 或者 ~./bash_profile文件对该用户生效

  • 如果使用了zsh的话得加载在/etc/zsh/zshrc文件中


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1# apt安装的不用配置该项
2export GOROOT=/usr/local/go
3export PATH=$PATH:$GOROOT/bin
4
5# 这个是你自己的开发目录
6# 可以同时存在多个开发目录,用:连接
7export GOPATH=$HOME/vscode/go-config
8export GOBIN=$GOPATH/bin
9export PATH=$PATH:$GOBIN
10
11# 如果原先有老得go环境变量,还要删除
12export PATH=${PATH#/*/tiger/go/go/bin}
13
14
  • **生效配置:**source /etc/profile 或者source ~/.profile

安装插件(vscode)

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C++ explicit关键字

2022-1-11 12:36:11

安全经验

安全开源项目网址

2019-11-28 7:40:04

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索