Use g to switch to different versions of golang on windows
GitHub repository address
/voidint/g
GitHub download connection
/voidint/g/releases
Windows Installation
It is best to choose the latest version to experience the latest features
1. After entering the download link, the download suffix is
.
The latest version of the compressed package
2. Create a custom directory (the directory here can be set by itself, as long as the configured environment variables are unified with this): D:\g
3. Configure environment variables
Win11 location:System > System Information > Advanced System Settings > Environment Variables (N)... > System Variables (S)
Other Windows versions can be found on Baidu
Notice:This refers to creating new variables and values in system variables; adding values to the Path variable in system variables; after configuration, be sure to click OK to close the window.
#System Variables
#Set up mirrors, domestic mirrors cannot be accessed freely in China. To ensure the current installation process, set up domestic mirrors
Variable: G_MIRROR
Value: /dl/
#Set g's working directory (go's download and installation directory), which is configured as the root directory
Variable: G_HOME
Value (here is consistent with the above custom directory): D:\g
#Configure GOROOT, this point to go in the working directory of g. After g installs the go version, it will softly link to the specified version in the versions directory in this path to control the current go version. If go has been installed before installing g , the GOROOT environment variable needs to be modified.
Variable: GOROOT
Value: %G_HOME%\go
#Enable all experimental features, configure the configuration to support custom installation directory, if you do not enable the default download, it will be installed in the default directory by default in C:\Users\your username\.g directory (and G_HOME will be automatically set to the default directory, set G_HOME will be invalid)
Variable: G_EXPERIMENTAL
Value: true
#Configure GOBIN
Variable: GOBIN
Value: %GOROOT%\bin
#Add value of variable Path
#Set the directory (and the directory where the file is located), so that you can access it at any time using the command line
Value (here is consistent with the above custom directory): D:\g
#Configure golang execution file directory
Value: %GOBIN%
4. Test
cmd terminal input: g env or g -v to view environment variable configuration or version information
The installation is successful after querying the relevant information
Notice:If you enter go version in the terminal tool and do not display the version, it may be that the GOBIN environment variable is not effective, and you need to turn it into a full path, such as the custom directory splicing \go\bin above (it needs to be spliced according to the custom path): D:\g\go\bin
Basic usage commands
g ls-remote: View the installable version of golang
g install version number: Download and install the specified version number version
g self update: automatically upgrade to the latest version
g ls: query the installed version of go
g ls-remote stable: query the go version of the stable status currently available for installation
g use version number: Switch to the specified version, need to be downloaded
g uninstall version number: uninstall an installed version of go