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?

# AWS学習ログ Day16 (2026-03-16)

0
Posted at

教材

CloudTech

学習時間

25分 × 1


パッケージ管理とは

Linuxではソフトウェアの単位をパッケージと呼ぶ。
パッケージの取得・インストール・更新・削除を管理するのがパッケージ管理コマンド

yum と dnf の関係

コマンド 特徴
yum RedHat系ディストリビューションで長く使われてきた標準コマンド
dnf yumの後継・拡張版。現在はこちらが主流

Amazon Linux 2023(本記事の実行環境)では dnf を使用する。


dnf コマンド一覧

インストール

# 最新版をインストール
dnf install {パッケージ名}

# バージョンを指定してインストール
dnf install {パッケージ名}-{バージョン}

バージョン一覧を確認してから指定インストールする例(httpd):

[root@ip-172-31-42-29 ~]# dnf list --showduplicates httpd
Last metadata expiration check: 0:02:06 ago on Mon Mar 16 07:02:39 2026.
Available Packages
httpd.x86_64    2.4.54-3.amzn2023.0.4    amazonlinux
httpd.x86_64    2.4.55-1.amzn2023        amazonlinux
httpd.x86_64    2.4.56-1.amzn2023        amazonlinux
...(省略)...
httpd.x86_64    2.4.66-1.amzn2023.0.1    amazonlinux

[root@ip-172-31-42-29 ~]# dnf install httpd-2.4.54-3.amzn2023.0.4

更新・削除・検索

dnf update                 # アップデート可能なパッケージをすべて更新
dnf update {パッケージ名}   # 指定パッケージのみ更新
dnf remove {パッケージ名}   # パッケージを削除
dnf search {パッケージ名}   # パッケージを検索

依存関係について

パッケージをインストールすると、動作に必要な別のパッケージ(依存パッケージ)も自動で取得される。

種別 インストール時の表示 内容
強い依存 Installing dependencies: ないと動かない。必須
弱い依存 Installing weak dependencies: なくても動くが、入れた方が望ましい

インストールとPATHの自動設定

dnf install でインストールされたコマンドは、自動的に /usr/bin/ 以下に配置され、PATHが通った状態になる。

[root@ip-172-31-42-29 ~]# dnf install htop
[root@ip-172-31-42-29 ~]# which htop
/usr/bin/htop

top コマンドと htop の違い:

コマンド 特徴
top 標準搭載。プロセスの一覧をリアルタイム表示。q で終了
htop 別途インストールが必要。視覚的に見やすく操作性が高い

リポジトリの実体

パッケージはリポジトリ(ダウンロード元サーバー)から取得される。
リポジトリの設定は /etc/yum.repos.d/ 以下の .repo ファイルで管理されている。

[root@ip-172-31-42-29 ~]# cd /etc/yum.repos.d/
[root@ip-172-31-42-29 yum.repos.d]# ls -l
total 8
-rw-r--r--. 1 root root 1028 Feb 10 20:31 amazonlinux.repo
-rw-r--r--. 1 root root  729 Feb 10 20:31 kernel-livepatch.repo

Amazon Linux 2023 の .repo ファイルには以下が含まれている:

  • mirrorlist:パッケージ取得先のURL(リージョン変数が埋め込まれている)
  • gpgcheck=1:GPG署名によるパッケージの改ざんチェック
  • enabled=0/1:リポジトリの有効・無効

EPEL(Extra Packages for Enterprise Linux)とは

Fedoraプロジェクトが提供する追加リポジトリ。
標準リポジトリには含まれないパッケージを、比較的安定した形で提供している。


サービス管理(systemctl)

LinuxではOSやミドルウェアの起動プロセスをサービスとして管理する。
systemctl コマンドを使って操作する。

主なコマンド

systemctl list-units --type=service   # 起動中のサービス一覧を表示
systemctl status {サービス名}          # サービスの状態を確認
systemctl start {サービス名}           # サービスを起動
systemctl stop {サービス名}            # サービスを停止
systemctl restart {サービス名}         # サービスを再起動(設定変更後の反映に使用)
systemctl enable {サービス名}          # OS再起動時に自動起動する設定

実行例:sshd の状態確認

[root@ip-172-31-42-29 ~]# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-03-16 06:56:30 UTC; 31min ago
   Main PID: 1551 (sshd)

enabled と表示されているため、次回のOS再起動時にも自動起動する。

実行例:httpd の起動・停止

# 起動前(inactive)
[root@ip-172-31-42-29 ~]# systemctl status httpd.service
○ httpd.service - The Apache HTTP Server
     Active: inactive (dead)

# 起動後(active running)
[root@ip-172-31-42-29 ~]# systemctl start httpd.service
[root@ip-172-31-42-29 ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
     Active: active (running) since Mon 2026-03-16 07:29:59 UTC; 2s ago
     Status: "Started, listening on: port 80"

よくあるミス・注意点

  • systemctl enable自動起動の設定であり、コマンド実行時点での即時起動は行わない。即時起動したい場合は start と併用する
# 起動 + 自動起動を同時に設定するワンライナー
systemctl enable --now httpd.service
  • restart はサービスを一度停止して再起動する。設定ファイルを変更した後に変更を反映させたいときに使う

感想

CloudtechのLinux基礎講座が完了した

次からAWSでの作業に戻るので楽しみ

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?