goenv

command module
v0.0.0-...-f07bf43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 13 Imported by: 0

README ΒΆ

Go Version Management: goenv

PR Checks Status Latest Release License Go Bash Linux macOS

goenv aims to be as simple as possible and follow the already established successful version management model of pyenv and rbenv.

πŸŽ‰ Now 100% Go-based with dynamic version fetching! No more static version files or manual updates needed.

This project was originally cloned from pyenv, modified for Go, and has now been completely rewritten in Go for better performance and maintainability.

asciicast

goenv does...
  • Let you change the global Go version on a per-user basis.
  • Provide support for per-project Go versions.
  • Smart version discovery - automatically detects versions from .go-version or go.mod
  • Go.mod toolchain support - respects Go 1.21+ toolchain directives with smart precedence
  • Allow you to override the Go version with an environment variable.
  • Search commands from multiple versions of Go at a time.
  • Provide tab completion for bash, zsh, fish, and PowerShell.
  • Automatically rehash after go install - tools available immediately (can be disabled with --no-rehash flag)
  • Enhanced diagnostics (goenv doctor) with interactive fix mode and 18 issue types
  • Quick status check (goenv status) for installation health overview
  • Version usage analysis (goenv versions --used) - scan projects to see which versions are in use
  • Version lifecycle tracking (goenv info) with EOL detection and upgrade recommendations
  • Version comparison (goenv compare) for side-by-side analysis
  • First-time setup wizard (goenv setup) for automatic shell and IDE configuration
  • Interactive beginner guide (goenv get-started) for new users
  • Command discovery (goenv explore) to find commands by intent or category
  • Self-update capability (goenv update) for both git and binary installations
  • Tool management (goenv tools) - comprehensive tool management across Go versions:
    • Install/uninstall tools across all versions with --all flag
    • Check tool consistency with goenv tools status
    • Find outdated tools with goenv tools outdated
    • Auto-install common tools with goenv tools default
    • Sync tools between versions with goenv tools sync
  • Version aliases (goenv alias) - create convenient shorthand names for versions
  • VS Code integration (goenv vscode) - sync Go settings with workspace-relative paths and security validation
  • Shell prompt integration (goenv prompt) - display active Go version in your shell prompt with smart caching
goenv compared to others:

New in 2.x: This version is a complete rewrite in Go, offering:

  • Dynamic version fetching - Always up-to-date without manual updates
  • Offline support - Works without internet via intelligent caching
  • Better performance - Native Go binary vs bash scripts
  • Cross-platform - Single binary for all supported platforms
  • Auto-rehash - Installed tools work immediately without manual intervention (configurable for CI/CD)

Hints
AWS CodeBuild

The following snippet can be inserted in your buildspec.yml (or buildspec definition) for AWS CodeBuild. It's recommended to do this during the pre_build phase.

Side Note: if you use the below steps, please unset your golang version in the buildspec and run the installer manually.

- (cd /root/.goenv && git pull)

πŸš€ Quick Start

The fastest way to get started. Download a pre-built binary - no Go installation needed!

# Automatic install (Linux/macOS)
curl -sfL https://raw.githubusercontent.com/go-nv/goenv/master/install.sh | bash

# Or download manually from releases:
# https://github.com/go-nv/goenv/releases/latest
# Automatic install (Windows)
iwr -useb https://raw.githubusercontent.com/go-nv/goenv/master/install.ps1 | iex

Then add to your shell config:

# Bash (~/.bash_profile or ~/.bashrc)
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
Option 2: Package Manager (macOS)

Homebrew:

brew install goenv

Then add to your shell config (see Option 1 above for shell configuration).

Option 3: Git Clone (Requires Go to Build)

For contributors or those who want the latest development version:

# 1. Clone goenv
git clone https://github.com/go-nv/goenv.git ~/.goenv

# 2. Build (requires Go)
cd ~/.goenv && make build

# 3. Add to your shell config (~/.bashrc, ~/.zshrc, etc.)
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"

# 4. Restart your shell
exec $SHELL
Next Steps (All Options)
# Enable tab completion (optional but recommended)
goenv completion --install

# Restart your shell
exec $SHELL

# Install and set a Go version (one command!)
goenv use 1.22.0 --global

# Or install first, then set
goenv install 1.22.0

# πŸ’‘ Shorthand: goenv 1.22.0 is an alias for goenv use 1.22.0
goenv 1.22.0  # Same as: goenv use 1.22.0

# Verify
go version

# Install tools (automatically isolated per version)
go install golang.org/x/tools/cmd/goimports@latest
goenv rehash  # Makes tools available as shims

πŸ’‘ Tools installed with go install are isolated per Go version:

  • Tools install to $HOME/go/{version}/bin/ (e.g., ~/go/1.22.0/bin/goimports)
  • Running goenv rehash creates shims that automatically use the right version
  • Switch Go versions β†’ tools switch too (no conflicts between versions)
  • See GOPATH Integration for complete details

See Installation Guide for platform-specific setup.


🎨 Shell Prompt Integration

Display your active Go version directly in your shell prompt for instant visual feedback:

# Quick setup with the interactive wizard
goenv prompt config

# Manual setup - add to your shell config:
# Bash/Zsh (~/.bashrc or ~/.zshrc)
export PS1='$(goenv prompt --prefix "(" --suffix ") ") '"$PS1"

# Fish (~/.config/fish/config.fish)
function fish_prompt
  set -l goenv_version (goenv prompt 2>/dev/null)
  test -n "$goenv_version"; and echo -n "($goenv_version) "
  # ... rest of your prompt
end

# PowerShell ($PROFILE)
function prompt {
  $goenvVersion = goenv prompt 2>$null
  if ($goenvVersion) {
    Write-Host "($goenvVersion) " -NoNewline -ForegroundColor Cyan
  }
  "PS $($PWD.Path)> "
}

Features:

  • Smart caching - minimal performance impact (< 50ms)
  • Customizable format - control prefix, suffix, and display format
  • Project-aware - show only in Go projects with --go-project-only
  • Hide system Go - use --no-system to hide when using system Go

Advanced options:

# Short version (1.23 instead of 1.23.2)
export PS1='$(goenv prompt --short) '"$PS1"

# Custom format with emoji
export PS1='$(goenv prompt --icon "🐹" --format "go:%s") '"$PS1"

# Show only in Go projects
export PS1='$(goenv prompt --go-project-only) '"$PS1"

# Environment variable configuration
export GOENV_PROMPT_PREFIX="["
export GOENV_PROMPT_SUFFIX="]"
export GOENV_PROMPT_FORMAT="go:%s"

See goenv prompt --help for all options.


🎯 Interactive Mode

goenv adapts to your workflow with three levels of interactivity:

Non-Interactive Mode (CI/Automation)

Perfect for scripts and CI/CD pipelines - auto-confirms all operations:

# Auto-confirm with --yes flag
goenv install 1.23.0 --yes
goenv uninstall 1.22.0 -y

# Or set globally
export GOENV_ASSUME_YES=1
goenv install 1.23.0

# Quiet mode (suppress output)
goenv install 1.23.0 --quiet

# Auto-detected in CI environments (GitHub Actions, GitLab CI, etc.)
Minimal Interactive Mode (Default)

Balances automation with safety - prompts only for critical operations:

# Default behavior
goenv uninstall 1.22.0
# Prompt: "Really uninstall Go 1.22.0? [y/N]"

goenv install 1.23.0
# Shows progress, offers retry on failure
Guided Interactive Mode (Learning)

Helpful prompts and suggestions for new users:

# Enable guided mode
goenv install --interactive
# Offers version selection, explains choices

goenv doctor --interactive  
# Offers to fix issues automatically

goenv use --interactive
# Guides through version selection
Global Flags
  • --interactive - Enable guided mode with helpful prompts
  • --yes / -y - Auto-confirm all prompts (non-interactive)
  • --quiet / -q - Suppress progress output (only show errors)
Environment Variables
  • GOENV_ASSUME_YES=1 - Auto-confirm globally (like --yes)
  • CI=true - Automatically enables non-interactive mode
Examples by Use Case

Daily development:

goenv install 1.23.0    # Default: shows progress, confirms if needed
goenv use 1.23.0        # Installs if needed (with prompt)

Automation scripts:

#!/bin/bash
goenv install 1.23.0 --yes
goenv global 1.23.0 --yes

CI/CD pipelines:

# goenv auto-detects CI - no flags needed
- run: goenv install 1.23.0
- run: goenv global 1.23.0

Learning mode:

goenv install --interactive  # Guided experience
goenv explain               # Understand version resolution

πŸ“– Full Guide: See Interactive Mode Guide for comprehensive documentation.


πŸͺ Hooks System

goenv includes a powerful hooks system that lets you automate actions at key points in the goenv lifecycle. Hooks are declarative, safe, and cross-platform.

Quick Example
# Generate configuration template
goenv hooks init

# Edit ~/.goenv/hooks.yaml
# Set enabled: true and acknowledged_risks: true

# Example: Log installations and send Slack notifications
hooks:
  post_install:
    - action: log_to_file
      params:
        path: ~/.goenv/install.log
        message: "Installed Go {version} at {timestamp}"

    - action: http_webhook
      params:
        url: https://hooks.slack.com/services/YOUR/WEBHOOK
        body: '{"text": "βœ… Go {version} installed"}'
Available Actions
  • log_to_file - Write audit logs and track installations
  • http_webhook - Send notifications to Slack, Discord, or custom APIs
  • notify_desktop - Display native desktop notifications
  • check_disk_space - Verify sufficient space before operations
  • set_env - Set environment variables dynamically
Hook Points

Execute actions at 8 different lifecycle points:

  • pre_install / post_install - Before/after installing Go versions
  • pre_uninstall / post_uninstall - Before/after removing Go versions
  • pre_exec / post_exec - Before/after executing Go commands
  • pre_rehash / post_rehash - Before/after regenerating shims
Commands
goenv hooks init       # Generate configuration template
goenv hooks list       # Show available actions and hook points
goenv hooks validate   # Check configuration for errors
goenv hooks test       # Dry-run hooks without executing

πŸ“– Complete Hooks Documentation - Examples, use cases, and detailed guides


πŸ“– Documentation

πŸ“š Complete Documentation - Comprehensive guides and references

Getting Started
Reference
Advanced Topics
For Contributors
Other

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
cmd
internal
cache
Package cache provides utilities and operations for managing Go build and module caches.
Package cache provides utilities and operations for managing Go build and module caches.
cgo
lifecycle
Package lifecycle provides Go version support status information
Package lifecycle provides Go version support status information
osinfo
Package osinfo provides zero-dependency operating system and architecture detection.
Package osinfo provides zero-dependency operating system and architecture detection.
session
Package session provides session-scoped state management for goenv operations.
Package session provides session-scoped state management for goenv operations.
shell/profile
Package profile provides high-level shell profile management operations.
Package profile provides high-level shell profile management operations.
shellutil
Package shellutil provides canonical implementations for shell detection, profile path resolution, and initialization command generation.
Package shellutil provides canonical implementations for shell detection, profile path resolution, and initialization command generation.
tools
Package tools provides utilities and operations for managing Go tools across versions.
Package tools provides utilities and operations for managing Go tools across versions.
toolupdater
Package toolupdater provides automatic update functionality for Go toolspkg.
Package toolupdater provides automatic update functionality for Go toolspkg.
scripts
build-tool command
swap command
test-stdlib command
test_windows_compatibility command
Windows Compatibility Test Suite Tests both runtime support and code quality for Windows compatibility
Windows Compatibility Test Suite Tests both runtime support and code quality for Windows compatibility
testing
testutil
Package testutil provides low-level test utilities with zero internal dependencies.
Package testutil provides low-level test utilities with zero internal dependencies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL