A collection of scripts for managing, installing, and switching between multiple Go versions.
English | ๆฅๆฌ่ช
- ๐ go-multi-version-manager
- These scripts are designed for Ubuntu; they are not supported on Mac and Windows
- For Go versions managed by
install_go_with_command.sh, ensure$HOME/go/binis included in yourPATH - Always verify installation with
go versionafter setup - When switching Go versions using
gomvm switch, the selected version persists across shell sessions and.bashrcreloads - For general Go installation guidance, refer to the official Go documentation
Important
gomvm automatically sets up Go environment configuration during installation. For more details, see Go Environment Variables and PATH Configuration Guide.
Automatic Setup: The installer adds the following single line to your ~/.bashrc:
# Go็ฐๅข่จญๅฎ - gomvm
[ -f "$HOME/.config/gomvm/go-env.sh" ] && source "$HOME/.config/gomvm/go-env.sh"This configuration enables:
- โ Version persistence across shell sessions
- โ Automatic version selection based on your saved preferences
- โ Clean separation of Go environment settings
- โ Easy maintenance through a single configuration file
Advanced Configuration: The actual Go environment logic is managed in ~/.config/gomvm/go-env.sh, which provides:
- Dynamic PATH management based on selected Go version
- Fallback to system defaults when no version is selected
- Optional latest version checking (disabled by default)
Note
After installation, the configuration is automatically applied. Manual setup is not required.
Tip
If you need more details about how gomvm manages Go environment variables and PATH settings, check the Go Environment Variables and PATH Configuration Guide.
The easiest way to set up go-multi-version-manager.
gomvm is added to $HOME/.local/bin/gomvm.
It can be added automatically by executing the following command.
# Download and run the installer script
curl -sSL https://raw.githubusercontent.com/7rikazhexde/go-multi-version-manager/main/gomvm-install.sh | bash
# Load updated PATH settings
source ~/.bashrcAlternatively, you can clone the repository and set it up manually.
# Clone the repository
git clone https://github.com/7rikazhexde/go-multi-version-manager.git
cd go-multi-version-manager
# Set up gomvm
./gomvm setup
# Load updated PATH settings
source ~/.bashrcTo completely remove gomvm from your system, run the following command.
curl -sSL https://raw.githubusercontent.com/7rikazhexde/go-multi-version-manager/main/gomvm-uninstall.sh | bashThis uninstallation script performs the following actions.
- ๐งน Removes the gomvm repository directory from your system
- ๐งน Deletes the configuration directory (
~/.config/gomvm) - ๐งน Removes the gomvm binary from
~/.local/bin - ๐งน Cleans up Go environment settings from
~/.bashrc
Warning
The uninstallation process does not remove the following.
- Go versions installed in
$HOME/go/bin(installed viagomvm install) - Go versions installed in system directories (e.g.,
/usr/local/go)
If you want to completely remove everything, you can manually delete the following.
- Go versions in
$HOME/go/bin/ - The default Go installation in
/usr/local/go
After installation, you can use the following commands.
# List available Go versions
gomvm list
# Install a specific Go version
gomvm install 1.24.1
# List installed Go versions
gomvm installed
# Uninstall a specific Go version
gomvm uninstall 1.24.1To switch between installed Go versions.
# Switch to Go 1.24.1
source gomvm switch 1.24.1The switch command will:
- ๐ Change the Go version for your current shell session
- ๐พ Save your version preference to make it persist across shell sessions
- ๐ Ensure the selected version remains active even after reloading
.bashrc
Important
source command with switch to make the changes take effect in your current shell.
If you wish to return to the system default Go version, you can either:
- ๐๏ธ Delete the saved preference:
rm $HOME/.go_selected_version - ๐ Then reload your shell:
source ~/.bashrc
The latest version check feature is disabled by default to avoid unnecessary network requests. To enable it:
-
โ๏ธ Edit the Go environment configuration file:
nano ~/.config/gomvm/go-env.sh -
๐ Find the commented line:
# source "$SCRIPT_PATH" # ใใฎ่กใฎใณใกใณใใ่งฃ้คใใใจๆๆฐใใผใธใงใณใใงใใฏใๆๅนใซใชใใพใ -
๐ง Uncomment it by removing the
#character:source "$SCRIPT_PATH" # ๆๆฐใใผใธใงใณใใงใใฏใๅฎ่ก
-
๐พ Save the file and reload your configuration:
source ~/.bashrc
Once enabled, this feature:
- ๐ Checks for the latest Go version at login
- โฑ๏ธ Only checks once per 24 hours to avoid excessive network requests
- ๐ก Suggests installation if the latest version isn't installed
- ๐ Can be forced to check using the
--forceoption, ignoring the 24-hour rule
To manually check for the latest version:
source ~/path/to/go-multi-version-manager/check_latest_go.sh --forceInstalls the default version of Go in /usr/local/go, replacing any existing version.
Usage:
./install_go_replace_default.sh 1.23.2The script will prompt you to confirm the deletion of /usr/local/go if it already exists, and then install the specified version.
Installs Go using the go install command, allowing multiple versions to be installed in ${HOME}/go/bin.
Usage:
./install_go_with_command.sh 1.23.1The script installs the specified version and places it in ${HOME}/go/bin/go<version>.
Installs a specific version of Go in /usr/local/go<version>. If the specified version is already installed, it will be skipped.
Usage:
./install_go_specific.sh 1.23.0This script allows for multiple versions to be installed in separate directories.
Switches to a specified Go version. Run this script with source to use the specified Go version in the current shell session and to save it as the default for future sessions. If the specified Go version is not installed, this script will automatically install it.
Usage:
source ./switch_go_version.sh 1.23.0Fetches a list of available Go versions from the official download page.
Usage:
./list_go_versions.shThis script retrieves all available versions from the Go download page and displays them.
To help maintain code quality, you can set up a pre-commit hook that automatically runs shellcheck on all shell scripts before each commit.
-
Install
shellchecksudo apt install shellcheck
-
Add Execution Permission
chmod +x scripts/ci/create_pre-commit.sh
-
Run the Create Pre-commit Script
./scripts/ci/create_pre-commit.sh
This will create a pre-commit hook under .git/hooks/ that will automatically check all .sh files in scripts/ubuntu before each commit.
To run the pre-commit hook manually, execute .git/hooks/pre-commit.