LoginSignup
1
0

More than 1 year has passed since last update.

Ubuntu で Go の最新版を使う

Last updated at Posted at 2021-12-08

Ubuntu 20.04 にて Go の最新版を使う手順です。
Windows 10 WSL2 上の Ubuntu の場合は、下記手順となります。

最新の golang-go リポジトリを追加する

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go

なお、 golang-go は 最新の Go をデフォルトのGoとしてインストールします。
代わりに golang-1.17 をインストールしたい場合、 /usr/lib/go-1.17/bin のバイナリを使用してください。

パッケージを更新する

パッケージを更新したい場合は、いつもの手順でOKです。

sudo apt update
sudo apt upgrade

Hello World

動作確認をしてみます。
hello フォルダを作成し、 go mod init にて hello フォルダに モジュールを作成します。
go.mod ファイルが作成されます。

$ mkdir hello
$ cd hello
$ go mod init example/hello
go: creating new go.mod: module example/hello

hello.go として保存します。

hello.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

実行してみます。

$ go run .
Hello, World!

参考

1
0
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
1
0