1,075
社区成员




g
是一个Linux、macOS、Windows下的命令行工具,可以提供一个便捷的多版本go环境的管理和切换。
1.github上的g:https://github.com/voidint/g/releases
Linux/macOS(适用于bash、zsh)
- # 建议安装前清空`GOROOT`、`GOBIN`等环境变量
- $ curl -sSL https://raw.githubusercontent.com/voidint/g/master/install.sh | bash
- $ echo "unalias g" >> ~/.bashrc # 可选。若其他程序(如'git')使用了'g'作为别名。
- $ source ~/.bashrc # 或者 source ~/.zshrc
下载release的二进制压缩包
将压缩包解压至PATH
环境变量目录下(如/usr/local/bin
)
编辑shell环境配置文件(如~/.bashrc
、~/.zshrc
...)
- $ cat>>~/.bashrc<<'EOF'
- export GOROOT="${HOME}/.g/go"
- export PATH="${HOME}/.g/go/bin:$PATH"
- export G_MIRROR=https://golang.google.cn/dl/
- EOF
启用环境变量
$ source ~/.bashrc # 或source ~/.zshrc
下载后解压出来只有一个exe文件,把它放在一个单独的目录
示例:D:\g\g.exe
开始配置环境变量,都以g为演示
查询当前可供安装的stable
状态的go版本
- $ g ls-remote stable
- 1.13.15
- 1.14.7
安装目标go版本1.14.7
- $ g install 1.14.7
- Downloading 100% |███████████████| (119/119 MB, 9.939 MB/s) [12s:0s]
- Computing checksum with SHA256
- Checksums matched
- Now using go1.14.7
查询已安装的go版本
- $ g ls
- 1.7.6
- 1.11.13
- 1.12.17
- 1.13.15
- 1.14.6
- * 1.14.7
查询可供安装的所有go版本
- $ g ls-remote
- 1
- 1.2.2
- 1.3
- 1.3.1
- ... // 省略若干版本
- 1.14.5
- 1.14.6
- * 1.14.7
- 1.15rc1
切换到另一个已安装的go版本
- $ g use 1.14.6
- go version go1.14.6 darwin/amd64
卸载一个已安装的go版本
- $ g uninstall 1.14.7
- Uninstalled go1.14.7
- git clone https://github.com/goplus/gop.git
- cd gop
- # On mac/linux run:
- ./all.bash
- # On Windows run:
- all.bat
- 提示:实际上, all.bash 和 all.bat 内部都会执行 go run cmd/install.go
- C:\Users\lang>gop
- Gop is a tool for managing Go+ source code.
-
- Usage:
-
- gop <command> [arguments]
-
- The commands are:
-
- run Run a Go+ program
- go Convert Go+ packages into Go packages
- fmt Format Go+ packages
- mod module maintenance
- install Build Go+ files and install target to GOBIN
- build Build Go+ files
- clean Clean all Go+ auto generated files
- env prints Go+ environment information.
- test Test Go+ packages
- version Version prints the build information for Gop executables
-
- Use "gop help <command>" for more information about a command.
-
-
- C:\Users\lang>gop version
- gop v1.0.x windows/amd64
工欲善其事必先利其器,我们要开发gop代码,当然ide增强是必不可少的,vscode上的goplus插件提供了语法高亮、代码补全等功能。
新建gop文件夹,并在vs code中打开项目。
执行初始化与获取builtin
- go mod init gop
-
- go get github.com/goplus/gop/builtin
学到了