Skip to content

This repository contains scripts for managing, installing, and switching between multiple Go versions.

License

Notifications You must be signed in to change notification settings

7rikazhexde/go-multi-version-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”„ go-multi-version-manager

A collection of scripts for managing, installing, and switching between multiple Go versions.

English | ๆ—ฅๆœฌ่ชž

๐Ÿ“‹ Table of Contents

โš ๏ธ Notes

  • 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/bin is included in your PATH
  • Always verify installation with go version after setup
  • When switching Go versions using gomvm switch, the selected version persists across shell sessions and .bashrc reloads
  • For general Go installation guidance, refer to the official Go documentation

๐Ÿ“‹ Prerequisite

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.

๐Ÿ“ฅ Installation

๐Ÿ”„ Automatic Installation

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 ~/.bashrc

๐Ÿ‘จโ€๐Ÿ’ป Manual Installation

Alternatively, 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 ~/.bashrc

๐Ÿ—‘๏ธ Automatic Uninstallation

To 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 | bash

This 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 via gomvm 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.

  1. Go versions in $HOME/go/bin/
  2. The default Go installation in /usr/local/go

๐Ÿš€ Usage

๐Ÿ’ป Basic Commands

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.1

๐Ÿ”„ Switching Go Versions

To switch between installed Go versions.

# Switch to Go 1.24.1
source gomvm switch 1.24.1

The switch command will:

  1. ๐Ÿ”€ Change the Go version for your current shell session
  2. ๐Ÿ’พ Save your version preference to make it persist across shell sessions
  3. ๐Ÿ”’ Ensure the selected version remains active even after reloading .bashrc

Important

โš ๏ธ Always use the 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

๐Ÿ” Enabling Latest Version Check

The latest version check feature is disabled by default to avoid unnecessary network requests. To enable it:

  1. โœ๏ธ Edit the Go environment configuration file:

    nano ~/.config/gomvm/go-env.sh
  2. ๐Ÿ”Ž Find the commented line:

    # source "$SCRIPT_PATH"  # ใ“ใฎ่กŒใฎใ‚ณใƒกใƒณใƒˆใ‚’่งฃ้™คใ™ใ‚‹ใจๆœ€ๆ–ฐใƒใƒผใ‚ธใƒงใƒณใƒใ‚งใƒƒใ‚ฏใŒๆœ‰ๅŠนใซใชใ‚Šใพใ™
  3. ๐Ÿ”ง Uncomment it by removing the # character:

    source "$SCRIPT_PATH"  # ๆœ€ๆ–ฐใƒใƒผใ‚ธใƒงใƒณใƒใ‚งใƒƒใ‚ฏใ‚’ๅฎŸ่กŒ
  4. ๐Ÿ’พ 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 --force option, ignoring the 24-hour rule

To manually check for the latest version:

source ~/path/to/go-multi-version-manager/check_latest_go.sh --force

๐Ÿ“œ Scripts

๐Ÿ“„ install_go_replace_default.sh

Installs the default version of Go in /usr/local/go, replacing any existing version.

Usage:

./install_go_replace_default.sh 1.23.2

The script will prompt you to confirm the deletion of /usr/local/go if it already exists, and then install the specified version.

๐Ÿ“„ install_go_with_command.sh

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.1

The script installs the specified version and places it in ${HOME}/go/bin/go<version>.

๐Ÿ“„ install_go_specific.sh

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.0

This script allows for multiple versions to be installed in separate directories.

๐Ÿ“„ switch_go_version.sh

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.0

๐Ÿ“„ list_go_versions.sh

Fetches a list of available Go versions from the official download page.

Usage:

./list_go_versions.sh

This script retrieves all available versions from the Go download page and displays them.

๐Ÿ› ๏ธ Developer Options

๐Ÿ”— Setting Up Pre-commit Hook for Shell Scripts

To help maintain code quality, you can set up a pre-commit hook that automatically runs shellcheck on all shell scripts before each commit.

๐Ÿ“ Steps to Set Up Pre-commit Hook

  1. Install shellcheck

    sudo apt install shellcheck
  2. Add Execution Permission

    chmod +x scripts/ci/create_pre-commit.sh
  3. 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.

About

This repository contains scripts for managing, installing, and switching between multiple Go versions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages