在新启动的Ubuntu容器中安装nginx出现报错
root@7ae3dcc48494:/# apt-get install -y nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package nginx
安装失败
解决办法:
先执行apt-get update,这个命令的作用是:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
在去安装nginx
操作结果
root@7ae3dcc48494:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [645 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [1167 B]
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [495 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [103 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [136 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [885 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [881 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [30.4 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [4250 B]
Fetched 16.6 MB in 9s (1795 kB/s)
Reading package lists... Done
root@7ae3dcc48494:/# apt-get install -y nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
root@7ae3dcc48494:/# nginx -v
nginx version: nginx/1.18.0 (Ubuntu)
安装成功