LoginSignup
30
13

More than 3 years have passed since last update.

Go Modulesでgo.modのGo versionを変更するには

Posted at

Go 1.13がリリースされ、Go 1.12 時代から Go Modulesを利用していたプロジェクトでは、go.modファイルのGoバージョンを変更したいですね。

go.modファイルはgo mod editで変更を加えることができます。go helpで使用方法を見ると、editing flagsというflagを指定することでどのように変更を加えたいかを指定します。

$ go help mod edit
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.

今回は、Goのバージョンを1.12から1.13へ変更したいので、次のediting flagsがその用途に該当します。

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

この説明の通り、所定プロジェクトのgo.modファイルが有るディレクトリにて、

go mod edit -go=1.13

とすることで、go.modファイルのGoバージョンが1.13に変更されます。

以上で、さくっとgo.modのGoバージョンを変更することができます。go helpで書かれている説明は非常にわかりやすいので、こまったらgo helpしてみるといいでしょう。

30
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
13