**Note:** The master branch may still be under development and may not represent a stable version. Please download stable versions of the source code through tags or download compiled binary executables through [release](https://github.com/voidint/g/releases).
`g` is a command-line tool for Linux, macOS, and Windows that provides convenient management and switching of multiple versions of the [Go](https://golang.org/) environment.
-下载[release](https://github.com/voidint/g/releases)的二进制压缩包,并解压至 g 家目录下的 bin 子目录中(即`~/.g/bin`目录)。
-将所需的环境变量写入`~/.g/env`文件
### Manual Installation(for Linux/macOS)
-Create a directory for `g` (recommended: `~/.g`)
-Download the binary compressed file from [releases](https://github.com/voidint/g/releases) and unzip it into the `bin` subdirectory of the `g` directory (i.e. `~/.g/bin`).
-Write necessary environment variables into `~/.g/env` file.
-Download the binary compressed file for Windows version from [releases](https://github.com/voidint/g/releases), and after unzipping it, put it in the ~/.g/bin directory.
-The default binary file name is `g.exe`, if you have already used `g` as an abbreviation for Git command, you can change `g.exe` to another name, such as `gvm.exe`.
-Run the command `code $PROFILE`, this command will open the default PowerShell configuration file using VSCode.
-Add the following content to the default PowerShell configuration file:
You are up to date! g v1.5.0 is the latest version.
```
卸载 g 软件本身
To uninstall the `g` software itself:
```shell
$ g self uninstall
...
...
@@ -189,46 +190,46 @@ Remove /Users/voidint/.g
## FAQ
-环境变量`G_MIRROR`有什么作用?
-What is the purpose of the environment variable `G_MIRROR`?
由于中国大陆无法自由访问 Golang 官网,导致查询及下载 go 版本都变得困难,因此可以通过该环境变量指定一个或多个镜像站点(多个镜像站点之间使用英文逗号分隔),g 将从该站点查询、下载可用的 go 版本。已知的可用镜像站点如下:
Due to the restricted access to the Golang official website in mainland China, it has become difficult to query and download go versions. Therefore, the environment variable `G_MIRROR` can be used to specify one or multiple mirror sites (separated by commas) from which g will query and download available go versions. The known available mirror sites are as follows:
- Go 官方镜像站点:https://golang.google.cn/dl/
- Go 语言中文网:https://studygolang.com/dl
-阿里云开源镜像站点:https://mirrors.aliyun.com/golang/
- Go official mirror site: https://golang.google.cn/dl/
- Go 语言中文网: https://studygolang.com/dl
-Aliyun open source mirror site: https://mirrors.aliyun.com/golang/
-环境变量`G_EXPERIMENTAL`有什么作用?
-What is the purpose of the environment variable `G_EXPERIMENTAL`?
当该环境变量的值为`true`时,将**开启所有的实验特性**。
When the value of this environment variable is set to true, it enables all experimental features.
-环境变量`G_HOME`有什么作用?
-What is the purpose of the environment variable `G_HOME`?
By convention, g uses the `~/.g` directory as its home directory. If you want to customize the home directory (especially for Windows users), you can use the G_HOME environment variable to switch to another directory. Since this feature is still experimental, it requires enabling the experimental feature switch `G_EXPERIMENTAL=true` to take effect. Please note that this solution is not perfect, which is why it is classified as an experimental feature. For more details, please refer to [#18](https://github.com/voidint/g/issues/18).
-macOS 系统下安装 go 版本,g 抛出`[g] Installation package not found`字样的错误提示,是什么原因?
-On macOS, when installing a go version, g throws an error message saying `[g] Installation package not found.` What is the reason?
Go 官方在**1.16**版本中才[加入了对 ARM 架构的 macOS 系统的支持](https://go.dev/doc/go1.16#darwin)。因此,ARM 架构的 macOS 系统下均无法安装 1.15 及以下的版本的 go 安装包。若尝试安装这些版本,g 会抛出`[g] Installation package not found`的错误信息。
The Go official support for ARM architecture on macOS was introduced in version [1.16](https://go.dev/doc/go1.16#darwin). Therefore, go installation packages of version 1.15 and earlier cannot be installed on ARM-based macOS systems. If you attempt to install these versions, g will throw an error message `[g] Installation package not found.`
Yes, it supports network proxy. You can set the network proxy address in environment variables such as `HTTP_PROXY`, `HTTPS_PROXY`, `http_proxy`, and `https_proxy`.
-支持哪些 Windows 版本?
-Which versions of Windows are supported?
因为`g`的实现上依赖于`符号链接`,因此操作系统必须是`Windows Vista`及以上版本。
Since g relies on symbolic links, the operating system must be Windows Vista or above.
- Windows 版本安装以后不生效?
- Why doesn't g work after installing it on Windows?
This may be because the downloaded and installed files are not added to the `$Path`. You need to manually add `$Path` to the user's environment variables. For convenience, you can run the `path.ps1` PowerShell script provided in the project and then restart your computer.
-使用 g 安装了某个 go 版本后,执行`go version`命令,但输出的 go 版本号并非是所安装的那个版本,这是不是 bug ?
-After installing a go version using g, when running the `go version` command, the output shows a different version than the one installed. Is this a bug?
由于当前 shell 环境中`PATH`环境变量设置有误导致(建议执行`which go`查看二进制文件所在路径)。在未修改 g 家目录的情况下,二进制文件 go 的路径应该是`~/.g/go/bin/go`,如果不是这个路径,就说明`PATH`环境变量设置有误。
This is likely due to an incorrect setting of the `PATH` environment variable in the current shell environment (it is recommended to run `which go` to see the path of the go binary file). By default, the path to the go binary file should be `~/.g/go/bin/go`. If it is not this path, it means that the PATH environment variable is set incorrectly.
-支持源代码编译安装吗?
-Does g support compiling and installing from source code?
不支持
No, it does not support compiling and installing from source code.
Thanks to tools like [nvm](https://github.com/nvm-sh/nvm), [n](https://github.com/tj/n), [rvm](https://github.com/rvm/rvm) for providing valuable ideas.
- macOS 系统下安装 go 版本,g 抛出`[g] Installation package not found`字样的错误提示,是什么原因?
Go 官方在**1.16**版本中才[加入了对 ARM 架构的 macOS 系统的支持](https://go.dev/doc/go1.16#darwin)。因此,ARM 架构的 macOS 系统下均无法安装 1.15 及以下的版本的 go 安装包。若尝试安装这些版本,g 会抛出`[g] Installation package not found`的错误信息。