Qiitaにログインしてダークテーマを使ってみませんか?🌙

ログインするとOSの設定にあわせたテーマカラーを使用できます!

0

この記事は最終更新日から1年以上が経過しています。

aptが遅い 向き先変更 と 小ネタ少し

最終更新日 投稿日 2022年10月22日

最近、aptが遅いんですよね。ネットですでに情報が溢れていますが、簡単な向き先の変え方を取り上げてみました。最後にapt関連のあれこれも少し。

向き先変更の方法

sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y

を行った際に、ダウンロードが遅いんですよね。これ、リポジトリ参照先(向き先というらしいです)が、悪いんです。それを変更する方法を説明します。

結論からいいますと、

ls -l /etc/apt/

で表示される、

drwxr-xr-x 2 root root 4096 10月 21 22:09 apt.conf.d
drwxr-xr-x 2 root root 4096  4月  8  2022 auth.conf.d
drwxr-xr-x 2 root root 4096  4月  8  2022 keyrings
drwxr-xr-x 2 root root 4096  4月  8  2022 preferences.d
-rw-rw-r-- 1 root root 2824 10月 15 14:10 sources.list  //このファイル
drwxr-xr-x 2 root root 4096 10月 15 15:09 sources.list.d
-rw-r--r-- 1 root root  636 10月 15 15:09 trusted.gpg
drwxr-xr-x 2 root root 4096 10月 15 15:09 trusted.gpg.d

sources.listをいじるだけです。中身を見てみましょう。( 長っ。 )

#deb cdrom:[Ubuntu 22.04.1 LTS _Jammy Jellyfish_ - Release amd64 (20220809.1)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://jp.archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy universe
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://jp.archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://jp.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://jp.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

なおこの、sources.listですが、直接ダブルクルックしても開きません(UbuntuアプデのGUIが立ち上がります)。editorで開かないといけません!!

なお、編集する前に、

cp /etc/apt/sources.list ~/Documents/sources.list

とかして、必ずバックアップは取るようにしてください( 最悪上の長いのをコピペして復旧もできる、自己責任で。 )

ただし、sources.listは、

-rw-rw-r-- 1 root root 2824 10月 15 14:10 sources.list

の通り、-rw-rw-r--なのでこのままでは権限によっては編集できませんね。なので、

sudo chmod 666 /etc/apt/sources.list

として編集したあと、

sudo chmod 664 /etc/apt/sources.list

で戻してもいいと思います。おまかせします。

当方、vimmerじゃないのでtext編集はデフォルトのgeditまたはcodeを使っています。

ではここから始めていきましょう。

sudo chmod 666 /etc/apt/sources.list

としてから、

gedit /etc/apt/sources.list

あるいは、

code /etc/apt/sources.list

としてeditorで開いてください。

http://jp.archive.ubuntu.com/ubuntu/

を、

mirror://mirrors.ubuntu.com/mirrors.txt

Ctrl+Hとか用いて置換してください。

http://security.ubuntu.com/ubuntu

も同様に

mirror://mirrors.ubuntu.com/mirrors.txt

に置換してください。

Ctrl+Sで上書き保存し、

sudo chmod 664 /etc/apt/sources.list

で、安全のため権限を元に戻しておいてください。
念の為に修正後の全文を貼ります。( 長いけど大事です。 )

#deb cdrom:[Ubuntu 22.04.1 LTS _Jammy Jellyfish_ - Release amd64 (20220809.1)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy main restricted
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates main restricted
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy universe
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy universe
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates universe
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy multiverse
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy multiverse
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates multiverse
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-backports main restricted universe multiverse
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-backports main restricted universe multiverse

deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-security main restricted
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-security main restricted
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-security universe
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-security universe
deb mirror://mirrors.ubuntu.com/mirrors.txt jammy-security multiverse
# deb-src mirror://mirrors.ubuntu.com/mirrors.txt jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

無事に編集されていますね。

これで、

sudo apt update

をしてみましたが、特に問題は認めませんでした。

その他の話題あれこれ

記事書くほどじゃないけど小ネタ。最近多いのが、

sudo apt upgrade

ってしたときの、

以下のパッケージは保留されます:
  snapd

ってコメント。どうしたらいい?

sudo apt install snapd

とかって、installに持っていったらいいだけのことです。

E: Could not get lock /var/lib/apt/lists/lock. It is held by process 1052 (packagekitd)
N: Be aware that removing the lock file is not a solution and may break your system.
E: ディレクトリ /var/lib/apt/lists/ をロックできません

のときはどうしたらいいか?

sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock

ってしてます。がけっこう強引な方法なので自己責任でしてください。自験例では問題は出ておりません。

最後に、

Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro

が、微妙にうざいですね。

参考文献など

Ubuntuの高速化~リポジトリ参照先の変更 - Qiita <- 大いに参考にさせていただきました!

[Ubuntu][apt] /var/lib/apt/lists/lockが不正な状態になった場合の対応メモ - Qiita <- 同じく大いに参考にさせていただきました!

新規登録して、もっと便利にQiitaを使ってみよう

  1. あなたにマッチした記事をお届けします
  2. 便利な情報をあとで効率的に読み返せます
  3. ダークテーマを利用できます
ログインすると使える機能について

コメント

この記事にコメントはありません。

いいね以上の気持ちはコメントで

0