6

Managing multiple Go versions in a Mac environment

 1 year ago
source link: https://en.liqiang.io/post/Hb820u5TdzKEH3bJcLUWhcSPUL9S79HC?lang=US_EN
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

All Posts

Managing multiple Go versions in a Mac environment

@SOLUTION· 2022-10-22 11:23 · 12 min read

Overview

Since there are many projects to maintain, and since these projects have different histories, some may be written by myself, some may be taken over from others, one of the problems I am facing is that Go versions may not be consistent, but you dare not take the risk to upgrade to a consistent version, after all, the test coverage is not enough to give me confidence to do so.

So, for now, I’m sticking with the Go version specified by the project, so I have the need to use multiple Go versions locally. This article is about the Mac environment, but it should actually work in the Linux environment as well.

Managing multiple environments via brew



  1. [[email protected]]# brew install go # 1.17
  2. [[email protected]]# brew install [email protected]
  3. [[email protected]]# brew unlink go
  4. [[email protected]]# brew link [email protected]

Specify a version to run the code

If you don’t want to set a global fixed version, you can also specify a path to run a different version.

But you need to be careful with the GOPATH environment variable. If you use the same GOPATH for different versions of Go, once the higher version updates the dependent libraries, the lower version won’t work, very important.



  1. [[email protected]]# GOPATH=/Users/liqiang.io/Applications/srcs/gopath1.14 \
  2. /Users/liqiang.io/Applications/srcs/go1.14.6/bin/go test cmd/server/main*

Goland sets up multiple versions

Goland supports different versions of Go by default, and can also help you download.

Figure 1:Open Setting
48805bebb51a.png
Figure 2:Choose Go Version
2be5021bd0b5.png

If you think that’s not enough, then you can ask Goland to download one for you:

Figure 3:Download Button
ad7630de14d9.png
Figure 4:Select Version
29a78192545b.png

Various versions for you to choose from.

GOPATH

However, don’t forget to select a different GOPATH after switching Go versions as well:

Figure 5:Setup GOPATH
7271a3b06e63.png
© 2012-2020 路人的技术 版权所有. Powered by LauZoo. Theme based on Nuo.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK