0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ubuntu:20.04に最新のGolangをaptでインストールする

Last updated at Posted at 2025-04-22

対象環境

  • Ubuntu: 18.04, 20.04 or 22.04 (amd64, arm64 or armhf)

rootでの実行を前提としていますが、通常ユーザーでのインストールの場合はすべてのapt-getコマンドをsudo apt-getに置き換えて実行することでパーミッションのエラーを回避できると思われます。(未確認)

Dockerfileを作成

Dockerfile
# ベースイメージとしてUbuntu 20.04を使用
FROM ubuntu:20.04

# パッケージインストール時のプロンプトを避けるための環境変数を設定
ENV DEBIAN_FRONTEND=noninteractive
# コンテナのタイムゾーンを設定
ENV TZ=Asia/Tokyo

# パッケージリストを更新しsoftware-properties-commonパッケージをインストール
# add-apt-repositoryコマンドに必要
RUN apt-get update \
  && apt-get install -y software-properties-common

# Golangバックポートリポジトリを追加してGoをインストール
# 最新バージョンのGoのためにlongsleep/golang-backports PPAを使用
RUN add-apt-repository ppa:longsleep/golang-backports \
  && apt-get update \
  && apt-get install -y golang-go

Dockerイメージをビルド

docker build -t ubuntu_golang ./Dockerfile

バージョンを確認

% docker run -it ubuntu_golang go version
go version go1.24.2 linux/amd64

参考サイト

https://go.dev/wiki/Ubuntu
https://askubuntu.com/questions/593433/error-sudo-add-apt-repository-command-not-found


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?