In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use GVM to manage Go projects, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Use Go version Manager to manage multiple versions of the Go locale and its modules.
The Go language version Manager (GVM) is an open source tool for managing the Go language environment. GVM "pkgsets" supports the installation of multiple versions of Go and the management of modules for each project. Originally developed by Josh Bussdieker, GVM (like its rival Ruby RVM) allows you to create a development environment for each project or group of projects, separating different Go versions and package dependencies to provide greater flexibility and prevent problems caused by different versions.
There are several ways to manage Go packages, including Modules for Go 1.11, which is built into Go. I find GVM simple and intuitive, and even if I don't use it to manage packages, I still use it to manage different versions of Go.
Install GVM
Installing GVM is easy. The GVM repository installation documentation instructs you to download the installer script and transfer it to Bash to install:
Bash
< system GVM 仍在使用系统版本的 Go ,由 =>The symbol represents. You can use the gvm use command to switch your environment to use the newly installed go1.12.8:
[chris@marvin] $gvm use go1.12.8Now using version go1.12.8 [chris@marvin] $go versiongo version go1.12.8 linux/amd64
GVM makes it extremely easy to manage installed versions of Go, but it's more than that!
Use GVM pkgset
Right out of the box, Go has an excellent and frustrating way of managing packages and modules. By default, if you go get gets a package, it will be downloaded to the src and pkg directories in the $GOPATH directory, and then you can include it in your Go program using import. This makes it easy to obtain packages, especially for non-privileged users, without requiring sudo or root privileges (much like pip install-user in Python). However, it is very difficult to manage different versions of the same package in different projects.
There are many ways to try to fix or mitigate this problem, including experimental Go Modules (initial support added in Go version 1.11) and Go dep (Go Modules's "official experiment" and continuous iteration). Before I find GVM, I build and test it in a Go project's own Docker container to ensure separation.
GVM does a good job of managing and isolating packages between projects by using "pkgsets" to attach the new directory of the project to the default $GOPATH of the installed Go version, just as $PATH works on Unix/Linux systems.
Imagine how it works. First, install the new version of Go 1.12.9:
[chris@marvin] $echo $GOPATH/home/chris/.gvm/pkgsets/go1.12.8/global [chris@marvin] $gvm install go1.12.9Installing go1.12.9... * Compiling...go1.12.9 successfully installed [chris@marvin] $gvm use go1.12.9Now using version go1.12.9
When GVM is told to use the new version, it changes to the new $GOPATH, and the default gloabl pkgset applies to that version:
[chris@marvin] $echo $GOPATH/home/chris/.gvm/pkgsets/go1.12.9/global [chris@marvin] $gvm pkgset list gvm go package sets (go1.12.9) = > global
Although no additional packages are installed by default, the packages in the global pkgset are available to any project that uses that particular version of Go.
Now, suppose you are enabling a new project that requires a specific package. First, use GVM to create a new pkgset called introToGvm:
[chris@marvin] $gvm pkgset create introToGvm [chris@marvin] $gvm pkgset use introToGvmNow using version go1.12.9@introToGvm [chris@marvin] $gvm pkgset list gvm go package sets (go1.12.9) global= > introToGvm
As mentioned above, a new directory for pkgset is added to $GOPATH:
[chris@marvin] $echo $GOPATH/home/chris/.gvm/pkgsets/go1.12.9/introToGvm:/home/chris/.gvm/pkgsets/go1.12.9/global
Change the directory to the preset introToGvm path and check the directory structure, which is done here using awk and bash.
[chris@marvin] $cd $(awk-favored vig'{print $1}')
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.