gvm README

The project's README from github.com/moovweb/gvm. As one markdown file: README.md.

gvm

Build Status

By Josh Bussdieker (jbuss, jaja, jbussdieker) while working at Moovweb

Currently lovingly maintained by Benjamin Knigge

Pull requests and other any other contributions would be very much appreciated.

GVM provides an interface to manage Go versions.

Features

Background

When we started developing in Go mismatched dependencies and API changes plagued our build process and made it extremely difficult to merge with other peoples changes.

After nuking my entire GOROOT several times and rebuilding I decided to come up with a tool to oversee the process. It eventually evolved into what gvm is today.

Installing

To install:

  1. Install Bison:

    sudo apt-get install bison
    
  2. Install gvm:

    bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
    

Or if you are using zsh just change bash with zsh

Installing Go

gvm install go1.4
gvm use go1.4 [--default]

Once this is done Go will be in the path and ready to use. $GOROOT and $GOPATH are set automatically.

Additional options can be specified when installing Go:

Usage: gvm install [version] [options]
    -s,  --source=SOURCE      Install Go from specified source.
    -n,  --name=NAME          Override the default name for this version.
    -pb, --with-protobuf      Install Go protocol buffers.
    -b,  --with-build-tools   Install package build tools.
    -B,  --binary             Only install from binary.
         --prefer-binary      Attempt a binary install, falling back to source.
    -h,  --help               Display this message.
    

A Note on Compiling Go 1.5+

Go 1.5+ removed the C compilers from the toolchain and replaced them with one written in Go. Obviously, this creates a bootstrapping problem if you don't already have a working Go install. In order to compile Go 1.5+, make sure Go 1.4 is installed first. If Go 1.4 won't install try a later version (e.g. go1.5), just make sure you have the -B option after the version number.

gvm install go1.4 -B
gvm use go1.4
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.7

A Note on ARMv6 and ARMv7 architectures (32 bit)

Binary versions for ARMv6 architecture are available starting from Go 1.6. So, it is necessary to bootstrap with an existing binary version, then it will be possible compiling other versions. For instance, to bootstrap a setup, version 1.21.0 may be used:

gvm install go1.21.0 -B
gvm use go1.21.0

And then, compile any other version:

gvm install go1.20.7

To install Go 1.20+

Go 1.20+ requires go1.17.3+. Use the below:

gvm install go1.4 -B
gvm use go1.4
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.17.13
gvm use go1.17.13
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.20
gvm use go1.20

List Go Versions

To list all installed Go versions (The current version is prefixed with "=>"):

gvm list

To list all Go versions available for download:

gvm listall

Uninstalling

To completely remove gvm and all installed Go versions and packages:

gvm implode

If that doesn't work see the troubleshooting steps at the bottom of this page.

Mac OS X Requirements

xcode-select --install
brew update
brew install mercurial

Linux Requirements

Debian/Ubuntu

sudo apt-get install curl git mercurial make binutils bison gcc build-essential

Redhat/Centos

sudo yum install curl
sudo yum install git
sudo yum install make
sudo yum install bison
sudo yum install gcc
sudo yum install glibc-devel

FreeBSD Requirements

sudo pkg_add -r bash
sudo pkg_add -r git
sudo pkg_add -r mercurial

Vendoring Native Code and Dependencies

GVM supports vendoring package set-specific native code and related dependencies, which is useful if you need to qualify a new configuration or version of one of these dependencies against a last-known-good version in an isolated manner. Such behavior is critical to maintaining good release engineering and production environment hygiene.

As a convenience matter, GVM will furnish the following environment variables to aid in this manner if you want to decouple your work from what the operating system provides:

  1. ${GVM_OVERLAY_PREFIX} functions in a manner akin to a root directory hierarchy suitable for auto{conf,make,tools} where it could be passed in to ./configure --prefix=${GVM_OVERLAY_PREFIX} and not conflict with any existing operating system artifacts and hermetically be used by your workspace. This is suitable to use with C{PP,XX}FLAGS and LDFLAGS, but you will have to manage these yourself, since each tool that uses them is different.

  2. ${PATH} includes ${GVM_OVERLAY_PREFIX}/bin so that any tools you manually install will reside there, available for you.

  3. ${LD_LIBRARY_PATH} includes ${GVM_OVERLAY_PREFIX}/lib so that any runtime library searching can be fulfilled there on FreeBSD and Linux.

  4. ${DYLD_LIBRARY_PATH} includes ${GVM_OVERLAY_PREFIX}/lib so that any runtime library searching can be fulfilled there on Mac OS X.

  5. ${PKG_CONFIG_PATH} includes ${GVM_OVERLAY_PREFIX}/lib/pkgconfig so that pkg-config can automatically resolve any vendored dependencies.

Recipe for success:

gvm use go1.1
gvm pkgset use current-known-good
# Let's assume that this includes some C headers and native libraries, which
# Go's CGO facility wraps for us.  Let's assume that these native
# dependencies are at version V.
gvm pkgset create trial-next-version
# Let's assume that V+1 has come along and you want to safely trial it in
# your workspace.
gvm pkgset use trial-next-version
# Do your work here replicating current-known-good from above, but install
# V+1 into ${GVM_OVERLAY_PREFIX}.

See examples/native for a working example.

Troubleshooting

Sometimes especially during upgrades the state of gvm's files can get mixed up. This is mostly true for upgrade from older version than 0.0.8. Changes are slowing down and a LTR is imminent. But for now rm -rf ~/.gvm will always remove gvm. Stay tuned!

Gitter

gvm (moovweb/gvm)

Searching Database…

11.7K ·GitHub
这是做什么的?GVM(Go Version Manager)是一个 shell 工具,用于在一台电脑上安装、切换和管理多个 Go 版本,同时管理与之配套的 GOPATH 环境。
所以它是我在 shell 里运行的命令行工具,而不是一个库?没错——它是一套 bash/zsh 脚本,用来管理 Go 工具链本身,存放在你主目录下的 ~/.gvm 里。你永远不会把它 import 到 Go 代码里。
我怎么安装它,并跑起第一个 Go 版本?运行仓库里的 gvm-installer 脚本,然后执行 'gvm install go1.4' 和 'gvm use go1.4'(加上 --default 可以把它设为默认)。GOROOT 和 GOPATH 会自动设置好,Go 也会出现在你的 path 里。
我的电脑上需要提前装好什么?需要 bash 或 zsh,再加上构建依赖:curl、git、Mercurial、make、binutils、Bison 和 gcc。README 给出了 Debian/Ubuntu、RHEL/CentOS 和 FreeBSD 的软件包安装命令;macOS 还需要额外安装 Xcode Command Line Tools 和 Mercurial。
安装较新的 Go 版本时有什么坑吗?有:从 Go 1.5 起,编译器本身是用 Go 写的,所以从源码编译 Go 1.5 及以上版本需要先有一个可用的 Go 安装(先装 1.4)。用 -B 标志可以绕过这一点,直接安装预编译好的二进制包。
我能安装哪些 Go 版本?任何打了标签的发布版本都可以:README 里提到的标签有 60.3、go1、weekly.2011-11-08 和 tip,覆盖范围从 2011 年的古老版本、每周快照一直到最新的开发版。'gvm listall' 能列出所有可下载的版本。
它可以直接安装二进制的 Go,而不是从源码编译吗?可以:-B 表示只从二进制安装,--prefer-binary 会优先用二进制、失败时再回退到源码编译。其他安装选项还包括 --source(自定义源码)、--with-protobuf 和 --with-build-tools。
它为什么会被做出来?作者早年在 Moovweb 做 Go 开发时,因为依赖不匹配和 API 变动折腾个不停,好几次把整个 GOROOT 搞坏了,于是写了一个工具来管住整个过程——后来就演变成了 gvm。
gvm 现在还在积极维护吗?开发已经放缓:README 里提到改动正在减少,一个长期支持版本即将发布。目前由 Benjamin Knigge 维护,欢迎提交 pull request 和贡献代码。
What are similar projects?asdf, pyenv, nvm, dep, oh-my-posh, rye, mise, rbenv
Creator
moovweb
Size
0.8 MB
Stars
11.7K
Updated
CommitAug 14
Age
14y
Commits · 90 Days