In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use go language". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use go language".
What is GVM?
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. It was originally developed by Josh Bussdieker, and GVM, similar to 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 to prevent problems caused by different versions. GVM has the following main features:
Manage multiple versions of Go, including installing, uninstalling, and specifying a version of Go
View all officially available Go versions, as well as locally installed and default versions of Go
Manage multiple GOPATH and edit environment variables of Go
You can associate the current directory to the GOPATH
You can view the file differences under GOROOT
Go version switching is supported
Install GVM
GVM is essentially a SHELL script, and the thing behind it is to download the source code and then compile it in C. Therefore, you need to install some dependency packages before installing GVM.
# 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 # macOS $xcode-select-- install $brew update $brew install mercurial
After installing the dependent environment, the installation of GVM is also very simple. The official one-click installation script is provided, and you just need to run it directly.
If you are using zsh, you can change the previous bash to zsh. This command mainly checks the relevant dependent environment and downloads the files related to GVM, then creates the required directory and adds it to .bashrc or .zshrc:
[[- s "/ home/wcl/.gvm/scripts/gvm"]] & & source "/ home/wcl/.gvm/scripts/gvm"
Enables it to take effect automatically every time you log in to Shell.
Install and manage Go versions using GVM
Once GVM is installed, you can start using it to install and manage different versions of Go. First, you can use the gvm listall command to display the available Go versions that can be downloaded and compiled.
$gvm listall gvm gos (available) go1 go1.0.1 go1.0.2 go1.0.3...
To install a specific version of Go, simply run the gvm install command, where is the version to be installed. If you are working on a project that uses version 1.12.8 of Go, you can use the gvm install go1.12.8 command to install this version.
$gvm install go1.12.8 Installing go1.12.8... * Compiling... Go1.12.8 successfully installed!
After the installation is complete, after typing the gvm list command, you will see that both Go version 1.12.8 and the Go version that comes with the system (packaged using the operating system's package manager) exist at the same time.
$gvm list gvm gos (installed) go1.12.8 = > system
However, GVM still defaults to the Go version of the system, represented by the = > symbol next to it. You can use the gvm use command to switch to the newly installed version of go 1.12.8.
$gvm use go1.12.8 Now using version go1.12.8$ go version go version go1.12.8 linux/amd64
If you don't want to switch versions every time you hit the gvm use command, you can add the-- default parameter to specify that this version is used by default.
$gvm use go1.12.8-default
Isn't it easy! GVM makes it extremely easy to manage installed versions of Go, but it's more than that!
Because Go 1.5 uses bootstrap (compiling Go with Go), using gvm install go directly will report an error if there is no Go command at all in the system environment. Therefore, you must install Go 1.4 first.
# install version 1.4 first, and-B means only binary packages are installed. $gvm install go1.4-B $gvm use go1.4$ export GOROOT_BOOTSTRAP=$GOROOT # then install the 1.5 + version of $gvm install go1.12.8 using GVM pkgset
By default, if you get a package through go get, it will be downloaded to the src and pkg directories in the $GOPATH directory. Then you can use import to introduce it into your Go program. However, it becomes difficult to manage different versions of the same package in different projects.
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 Go installation, similar to $PATH on the Linux system. Let's look at an example and install a new version of Go 1.12.9.
$echo $GOPATH / home/chris/.gvm/pkgsets/go1.12.8/global $gvm install go1.12.9 Installing go1.12.9... * Compiling... Go1.12.9 successfully installed $gvm use go1.12.9 Now using version go1.12.9
When GVM is told to use a new version, it will replace it with a new $GOPATH,gloabl pkgset that will be used by default.
$echo $GOPATH / home/chris/.gvm/pkgsets/go1.12.9/global $gvm pkgset list gvm go package sets (go1.12.9) = > global
Although no additional packages are installed by default, the packages in global pkgset are available for any project that uses this particular version of Go.
Now, suppose you are starting a new project that requires a specific package. First, use GVM to create a new pkgset called introToGvm.
$gvm pkgset create introToGvm $gvm pkgset use introToGvm Now using version go1.12.9@introToGvm $gvm pkgset list gvm go package sets (go1.12.9) global = > introToGvm
As mentioned above, a new directory introToGvm with the same name as pkgset is added to $GOPATH.
$echo $GOPATH / home/chris/.gvm/pkgsets/go1.12.9/introToGvm:/home/chris/.gvm/pkgsets/go1.12.9/global
Next, verify the directory structure in the new directory introToGvm.
$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.