LinuxCommandLibrary

goenv

Manage multiple Go versions

TLDR

List all available goenv commands

$ goenv commands
copy

Install a specific version of Golang
$ goenv install [go_version]
copy

Use a specific version of Golang in the current project
$ goenv local [go_version]
copy

Set the default Golang version
$ goenv global [go_version]
copy

List all available Golang versions and highlight the default one
$ goenv versions
copy

Uninstall a given Go version
$ goenv uninstall [go_version]
copy

Run an executable with the selected Go version
$ goenv exec go run [go_version]
copy

SYNOPSIS

goenv command [arguments]

PARAMETERS

activate
    Activates a goenv environment. This command is deprecated; use 'goenv shell', 'goenv local', or 'goenv global' instead.

commands
    Lists all available goenv commands.

deactivate
    Deactivates the currently active goenv environment. This command is deprecated; use 'goenv shell', 'goenv local', or 'goenv global' instead.

doctor
    Diagnoses potential problems with your goenv installation.

exec
    Runs an executable by first preparing the environment as goenv would.

global
    Sets the global Python version. Creates or modifies the .goenv/version file in your home directory.

help
    Displays help information about goenv or a specific command.

init
    Initializes goenv in your shell. Adds commands to your shell's startup file (e.g., .bashrc, .zshrc).

install
    Installs a specific Python version. Downloads and compiles Python from source.

local
    Sets the local Python version for a directory. Creates or modifies the .python-version file in the current directory.

prefix
    Displays goenv's installation prefix.

rehash
    Regenerates goenv shims for all installed Python versions. Run this after installing or uninstalling a Python package.

root
    Displays the root directory where goenv installs Python versions.

shell
    Sets a shell-specific Python version. Only applies to the current shell session.

shims
    Lists all installed shims.

uninstall
    Uninstalls a specific Python version.

version
    Displays the current goenv version.

version-file
    Displays the path to the file that sets the current Python version.

version-name
    Displays the currently selected Python version name.

versions
    Lists all Python versions known to goenv.

which
    Displays the full path to an executable.

whence
    Lists all Python versions that contain the given executable.

DESCRIPTION

goenv is a tool to manage multiple Python versions side-by-side. It lets you easily switch between different Python environments, ensuring your projects use the correct dependencies and interpreter. Unlike system-wide Python installations, goenv installs Python versions in your home directory, avoiding conflicts with system tools. It works by modifying your PATH environment variable to prioritize shims—lightweight executables that intercept Python commands and route them to the appropriate version. This allows you to use specific Python versions on a per-project basis or globally. goenv simplifies development workflows by providing a consistent and isolated environment for each project.

Goenv itself is written in bash, so its lightweight and simple to install.

CAVEATS

Requires modifying your shell's startup file (.bashrc, .zshrc) to add goenv to your PATH. Incorrect configuration can lead to Python not being found or using the wrong version. Remember to run goenv rehash after installing new packages or Python versions.

INSTALLATION

Installation typically involves cloning the goenv repository from GitHub and adding the appropriate commands to your shell's startup file. Refer to the goenv documentation for detailed installation instructions specific to your operating system and shell.

USAGE EXAMPLES

  • Install Python 3.9.7: goenv install 3.9.7
  • Set the local Python version for the current directory: goenv local 3.9.7
  • Set the global Python version: goenv global 3.9.7
  • List all installed Python versions: goenv versions

HISTORY

goenv was created to address the challenges of managing multiple Python versions and dependencies in a consistent and reliable manner. Inspired by Ruby's RVM and rbenv, goenv provides a simple and elegant solution for switching between different Python environments without interfering with the system's Python installation. Initially, it focused on basic version management, but has since evolved to include features such as shims, rehash, and support for local and global version settings. It gained popularity amongst python developers. The project continues to be actively maintained and updated to support new Python versions and features.

SEE ALSO

pyenv(1), virtualenv(1)

Copied to clipboard