Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upgrade the go version in a go mod

Tags:

go

go-modules

What is the proper way to upgrade the go version in a go mod, specifically 1.13 to 1.14?
Do you simply edit the go.mod file and change go 1.13 to go 1.14?

I'm not asking about how to edit the go.mod file, I'm asking if it is proper to simply change the go version in the go.mod file, and everything else (all the dependencies) is still ok for the project?

like image 366
James Haskell Avatar asked Mar 13 '20 18:03

James Haskell


People also ask

How do I update my go module version?

You can upgrade or downgrade a dependency module by using Go tools to discover available versions, then add a different version as a dependency. To discover new versions use the go list command as described in Discovering available updates.

How do you update golang in go mod?

You will need to use the version in the import path for both go. mod imports ( require github.com/awesomerepo/pkg/v2 v2. 0.0 ), when importing the package through command line ( go get github.com/awesomerepo/pkg/[email protected] ) and when importing your package in your source files ( import "github.com/awesomerepo/pkg/v2 v2.

What is go mod version?

The go. mod file includes an explicit require directive for each module that provides any package transitively imported by a package or test in the main module. (At go 1.16 and lower, an indirect dependency is included only if minimal version selection would otherwise select a different version.)

What does +incompatible mean in go mod?

+incompatible means the dependency has a semver major version of 2 or higher and is not a Go module yet (it doesn't have go.


2 Answers

Command go: Edit go.mod from tools or scripts:

Usage:

go mod edit [editing flags] [go.mod]

Edit provides a command-line interface for editing go.mod, for use primarily by tools or scripts. It reads only go.mod; it does not look up information about the modules involved. By default, edit reads and writes the go.mod file of the main module, but a different target file can be specified after the editing flags.

...

The -go=version flag sets the expected Go language version.

So simply:

go mod edit -go=1.14

But you may also edit go.mod manually, it's a simple text file. go mod edit is primilary for scripts so making changes to go.mod can easily be automated.

like image 183
icza Avatar answered Oct 16 '22 21:10

icza


The answers supplied here helped me alot. But a little adjustment may be due especially for Windows users.

I used on the command prompt:

go mod edit -go 1.17

And not:

go mod edit -go=1.17

Note the omission of ''=" sign.

like image 9
Ebite Zion Avatar answered Oct 16 '22 21:10

Ebite Zion