apt install 時の404対応

ブログ開始の準備

ブログを始めるにあたり、どのサービスを使うか悩みました。
今は大きく、以下の形態が主流だと思っています。
1. はてなやアメブロなどのサービス一体型で運営
2. 個人でレンタルサーバを借りて、CMS(WordPressやMovable Type)を導入、運営

私は
・ドメイン取得やレンタルサーバがどのようなものかを知りたくて、使ってみたかった
・CMSも使ったことがないので、勉強のため触ってみたい
・CMSによっては自身でコーディングしてカスタマイズできるので、言語の勉強にもなりそう
という理由から、2の色々自分で準備する形態、かつCMSにWordPressを選んだわけですが、
WordPressがどういうものかを知らないうちに、レンタルサーバを契約するのは抵抗があります。
そのため、まずは手持ちのPCで動かせる環境を構築することを考えました。
ぱっと思いついた方法は以下になります。
(以下の3つ以外にも他にも思い付きはしたのですが、興味の強いものに絞った結果、3つになりました。)

1. AWSのEC2インスタンスを立ち上げる
2. Oracle VirtualBoxにLinuxをインストール
3. Windows Subsystem for Linux(WSL)を使って、Ubuntuをインストール

2.は仕事でも使っているので、1と3で悩みました。
1も仕事で使っていますが、Amazon Linux 2登場後、まだ触ったことがありません(冬休みに触ろう。。。)。
3については、これまで全く触ったことがありませんでした。
WSLがどういったものかも知りたいので、今回は3の案でローカル環境でWordPressを動かせるようにすることにしました。
(WSLがいまいちでも、VirtualBoxやbitnamiがありますしね。)

いざ環境構築

WSLなどの詳細なインストール手順は省略します。
(「Windows 10 WSL」といったキーワードで検索すると、すぐ見つかると思います。)

WSLのUbuntuに対し、次の環境をaptで導入しようとしました。

・apache
・php
・mysql

404

早速以下のコマンドを実行します。
sudo apt install apache2

ところが。

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libfreetype6
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0
ssl-cert
Suggested packages:
www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
liblua5.2-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 1409 kB/1729 kB of archives.
After this operation, 6978 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Err:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-bin amd64 2.4.29-1ubuntu4.2
404 Not Found [IP: n.n.n.n 80]
Err:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-utils amd64 2.4.29-1ubuntu4.2
404 Not Found [IP: n.n.n.n 80]
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2-data all 2.4.29-1ubuntu4.2
404 Not Found [IP: n.n.n.n 80]
Err:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 apache2 amd64 2.4.29-1ubuntu4.2
404 Not Found [IP: n.n.n.n 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-bin_2.4.29-1ubuntu4.2_amd64.deb 404 Not Found [IP: n.n.n.n 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.29-1ubuntu4.2_amd64.deb 404 Not Found [IP: n.n.n.n 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-data_2.4.29-1ubuntu4.2_all.deb 404 Not Found [IP: n.n.n.n 80]
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/a/apache2/apache2_2.4.29-1ubuntu4.2_amd64.deb 404 Not Found [IP: n.n.n.n 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

と、404となってしまい、インストールできません。(n.n.n.nはIPをマスクしています。)

aptコマンドの実行が久しぶりだったため、いきなり躓くのか。。。と、ここでやや焦り始めます。
(原因に気づいたら、この程度で焦るのは恥ずかしい。。。)

少し悩んだところ、パッケージリストが古い?
と思い、以下のコマンドを実行。

sudo apt-get update

Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]
Get:6 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [187 kB]
Get:7 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [72.7 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [91.7 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [50.4 kB]
Get:10 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1440 B]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [996 B]
Get:12 http://archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [419 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [157 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [7028 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/restricted Translation-en [3076 B]
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [571 kB]
Get:20 http://archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [152 kB]
Get:21 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [5708 B]
Get:22 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [3176 B]
Get:23 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [2852 B]
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-ht
cacheclean.service.
invoke-rc.d: could not determine current runlevel
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for ufw (0.35-5) ...

色々降ってきました。
再度installを実行すると、無事インストールできました。

まとめ

・WSLのUbuntuを使う場合、初めにapt-get updateしておいたほうが良いかも。

ぼやき

Linux、日ごろから触ろう。。。(;´・ω・)
設計書もいいけど、やっぱコード書いてコマンド叩かないとね。。。