ZhangZhihui's Blog  

 

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

 

echo 'export GOENV_ROOT="$HOME/.goenv"' >> ~/.bashrc

echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> ~/.bashrc

echo 'eval "$(goenv init -)"' >> ~/.bashrc

 

复制代码
zzh@ZZHPC:~$ goenv init -
export GOENV_SHELL=bash
export GOENV_ROOT=/home/zzh/.goenv
if [ "${PATH#*$GOENV_ROOT/shims}" = "${PATH}" ]; then
  export PATH="$PATH:$GOENV_ROOT/shims"
fi
source '/home/zzh/.goenv/libexec/../completions/goenv.bash'
command goenv rehash 2>/dev/null
goenv() {
  local command
  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "$(goenv "sh-$command" "$@")";;
  *)
    command goenv "$command" "$@";;
  esac
}
goenv rehash --only-manage-paths
复制代码

If you want goenv to manage GOPATH and GOROOT (recommended), add GOPATH and GOROOT to your shell after eval "$(goenv init -)".

 

复制代码
zzh@ZZHPC:~$ goenv
goenv 2.1.11
Usage: goenv <command> [<args>]

Some useful goenv commands are:
   commands    List all available commands of goenv
   local       Set or show the local application-specific Go version
   global      Set or show the global Go version
   shell       Set or show the shell-specific Go version
   install     Install a Go version using go-build
   uninstall   Uninstall a specific Go version
   rehash      Rehash goenv shims (run this after installing executables)
   version     Show the current Go version and its origin
   versions    List all Go versions available to goenv
   which       Display the full path to an executable
   whence      List all Go versions that contain the given executable

See 'goenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/go-nv/goenv#readme
复制代码

 

复制代码
zzh@ZZHPC:~$ goenv install 1.21.5
Downloading go1.21.5.linux-amd64.tar.gz...
-> go1.21.5.linux-amd64.tar.gz
############################################################################################################################################################## 100.0%############################################################################################################################################################## 100.0%
Installing Go Linux 64bit 1.21.5...
Installed Go Linux 64bit 1.21.5 to /home/zzh/.goenv/versions/1.21.5

zzh@ZZHPC:~$ go version
go version go1.21.5 linux/amd64
zzh@ZZHPC:~$ which go
/home/zzh/.goenv/shims/go
zzh@ZZHPC:~$ echo $GOROOT
/home/zzh/.goenv/versions/1.21.5
zzh@ZZHPC:~$ echo $GOPATH
/home/zzh/go/1.21.5
复制代码

 

zzh@ZZHPC:~/.goenv/versions/1.21.5$ grep GOPROXY go.env
GOPROXY=https://proxy.golang.org,direct
zzh@ZZHPC:~/.goenv/versions/1.21.5$ which go
/home/zzh/.goenv/shims/go
zzh@ZZHPC:~/.goenv/versions/1.21.5$ go env | grep GOPROXY
GOPROXY='https://goproxy.io,direct'

 

复制代码
zzh@ZZHPC:~$ diff --side-by-side origin.txt goenv.txt
GO111MODULE='on'						GO111MODULE='on'
GOARCH='amd64'							GOARCH='amd64'
GOBIN=''							GOBIN=''
GOCACHE='/home/zzh/.cache/go-build'				GOCACHE='/home/zzh/.cache/go-build'
GOENV='/home/zzh/.config/go/env'				GOENV='/home/zzh/.config/go/env'
GOEXE=''							GOEXE=''
GOEXPERIMENT=''							GOEXPERIMENT=''
GOFLAGS=''							GOFLAGS=''
GOHOSTARCH='amd64'						GOHOSTARCH='amd64'
GOHOSTOS='linux'						GOHOSTOS='linux'
GOINSECURE=''							GOINSECURE=''
GOMODCACHE='/home/zzh/go/pkg/mod'			      |	GOMODCACHE='/home/zzh/go/1.21.5/pkg/mod'
GONOPROXY=''							GONOPROXY=''
GONOSUMDB=''							GONOSUMDB=''
GOOS='linux'							GOOS='linux'
GOPATH='/home/zzh/go'					      |	GOPATH='/home/zzh/go/1.21.5'
GOPRIVATE=''							GOPRIVATE=''
GOPROXY='https://goproxy.io,direct'				GOPROXY='https://goproxy.io,direct'
GOROOT='/usr/local/go'					      |	GOROOT='/home/zzh/.goenv/versions/1.21.5'
GOSUMDB='sum.golang.org'					GOSUMDB='sum.golang.org'
GOTMPDIR=''							GOTMPDIR=''
GOTOOLCHAIN='auto'						GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'		      |	GOTOOLDIR='/home/zzh/.goenv/versions/1.21.5/pkg/tool/linux_am
GOVCS=''							GOVCS=''
GOVERSION='go1.21.1'					      |	GOVERSION='go1.21.5'
GCCGO='gccgo'							GCCGO='gccgo'
GOAMD64='v1'							GOAMD64='v1'
AR='ar'								AR='ar'
CC='gcc'							CC='gcc'
CXX='g++'							CXX='g++'
CGO_ENABLED='1'							CGO_ENABLED='1'
GOMOD='/dev/null'						GOMOD='/dev/null'
GOWORK=''							GOWORK=''
CGO_CFLAGS='-O2 -g'						CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''							CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'						CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'						CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'						CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'						PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessag |	GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessag
复制代码

 

复制代码
zzh@ZZHPC:~$ goenv uninstall 1.21.5
goenv: remove /home/zzh/.goenv/versions/1.21.5? y

zzh@ZZHPC:~$ goenv install 1.22.2
go-build: definition not found: 1.22.2

See all available versions with 'goenv install --list'.

If the version you need is missing, try upgrading goenv:

  cd /home/zzh/.goenv/plugins/go-build/../.. && git pull && cd -

zzh@ZZHPC:~/.goenv$ cd /home/zzh/.goenv

zzh@ZZHPC:~/.goenv$ git pull

zzh@ZZHPC:~/.goenv$ goenv install 1.22.2
Downloading go1.22.2.linux-amd64.tar.gz...
-> go1.22.2.linux-amd64.tar.gz
############################################################################################################################################################## 100.0%############################################################################################################################################################## 100.0%
Installing Go Linux 64bit 1.22.2...
Installed Go Linux 64bit 1.22.2 to /home/zzh/.goenv/versions/1.22.2
复制代码

 

zzh@ZZHPC:~$ goenv global 1.22.2

 

复制代码
zzh@ZZHPC:~/.goenv$ git pull

zzh@ZZHPC:~$ goenv uninstall 1.22.2
goenv: remove /home/zzh/.goenv/versions/1.22.2? y

zzh@ZZHPC:~$ goenv install 1.23.0
Downloading go1.23.0.linux-amd64.tar.gz...
-> go1.23.0.linux-amd64.tar.gz
############################################################################################################################################################## 100.0%############################################################################################################################################################## 100.0%
Installing Go Linux 64bit 1.23.0...
Installed Go Linux 64bit 1.23.0 to /home/zzh/.goenv/versions/1.23.0

zzh@ZZHPC:~$ goenv global 1.23.0
复制代码

 

posted on   ZhangZhihuiAAA  阅读(57)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示