330 words
2 minutes

Changing Ubuntu’s Package Mirror

2022-11-16
Views —

On a Tencent Cloud Ubuntu instance, installing packages with apt failed because the configured mirror could not be resolved:

Err:1 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 m4 amd64 1.4.18-1
Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
Ign:2 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 autoconf all 2.69-11
Ign:3 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 autotools-dev all 20180224.1
Ign:4 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 automake all 1:1.15.1-3ubuntu2
Err:2 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 autoconf all 2.69-11
Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
Err:3 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 autotools-dev all 20180224.1
Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
Err:4 http://mirrors.tencentyun.com/ubuntu bionic/main amd64 automake all 1:1.15.1-3ubuntu2
Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://mirrors.tencentyun.com/ubuntu/pool/main/m/m4/m4_1.4.18-1_amd64.deb Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://mirrors.tencentyun.com/ubuntu/pool/main/a/autoconf/autoconf_2.69-11_all.deb Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://mirrors.tencentyun.com/ubuntu/pool/main/a/autotools-dev/autotools-dev_20180224.1_all.deb Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
E: Failed to fetch http://mirrors.tencentyun.com/ubuntu/pool/main/a/automake-1.15/automake_1.15.1-3ubuntu2_all.deb Something wicked happened resolving 'mirrors.tencentyun.com:http' (-5 - No address associated with hostname)
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

mirrors.tencentyun.com appeared to be unavailable; even a ping failed. Switching the package mirror resolved the problem in this setup.

Back up the source list#

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bk

Open sources.list#

sudo vi /etc/apt/sources.list

Add the Aliyun mirror entries#

I added these entries at the beginning of /etc/apt/sources.list. They are for Ubuntu 18.04 Bionic, the release used in this November 2022 post:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

Refresh the package lists and upgrade#

sudo apt-get update
sudo apt-get upgrade
Changing Ubuntu’s Package Mirror
https://blog.coding1024.com/en/posts/fde212d5/
Author
huangjx
Published at
2022-11-16
License
CC BY-NC-SA 4.0

Comments

Questions, ideas and experiences are welcome. Please be kind and avoid sharing private information.

Loading comments…