Ubuntu Docker环境安装google-chrome-stable时遭遇依赖缺失问题
Ubuntu Xenial安装Google Chrome Stable依赖失败的解决办法
问题说明
基于Ubuntu 16 Xenial的Docker镜像中安装google-chrome-stable,此前运行正常,近期构建时出现依赖错误:
Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: google-chrome-stable : Depends: libu2f-udev but it is not installable E: Unable to correct problems, you have held broken packages.
原因是Google Chrome近期将libu2f-udev从推荐依赖改为强制依赖,但Ubuntu Xenial的官方源中没有该包。
涉及的Dockerfile片段:
FROM -.dkr.ecr.us-east-1.amazonaws.com/ubuntu:xenial EXPOSE 9222 # Install ubuntu dependencies RUN apt-get update && \ apt-get -y upgrade && \ apt-get install -yq curl libgconf-2-4 # Install Google Chrome Stable RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ apt-get install -y wget gnupg && \ echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main' >> /etc/apt/sources.list.d/google-chrome.list && \ apt-get update && \ apt-get install -y --no-install-recommends \ google-chrome-stable \ fonts-ipafont-gothic \ fonts-wqy-zenhei \ fonts-thai-tlwg \ fonts-kacst ttf-freefont && \ rm -fr /var/lib/apt/lists/* && \ apt-get purge --auto-remove -y curl && \ rm -fr /src/*.deb
解决办法
临时修复(保留Xenial)
由于Xenial已停止标准支持,官方源无libu2f-udev,可从Ubuntu 17.10(Artful)源获取该包,修改Dockerfile的Chrome安装步骤如下:
# Install Google Chrome Stable RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ apt-get install -y wget gnupg && \ # 添加Artful源以获取libu2f-udev echo 'deb http://archive.ubuntu.com/ubuntu artful main universe' >> /etc/apt/sources.list && \ apt-get update && \ # 先安装依赖包 apt-get install -y libu2f-udev && \ # 添加Chrome官方源 echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb stable main' >> /etc/apt/sources.list.d/google-chrome.list && \ apt-get update && \ apt-get install -y --no-install-recommends \ google-chrome-stable \ fonts-ipafont-gothic \ fonts-wqy-zenhei \ fonts-thai-tlwg \ fonts-kacst ttf-freefont && \ # 移除Artful源避免后续冲突 sed -i '/artful/d' /etc/apt/sources.list && \ rm -fr /var/lib/apt/lists/* && \ apt-get purge --auto-remove -y curl && \ rm -fr /src/*.deb
⚠️ 注意:Artful同样已停止支持,此方法仅为临时 workaround,存在潜在安全风险。
长期方案:升级Ubuntu版本
Ubuntu 16 Xenial已结束标准支持,后续会持续出现依赖缺失、安全补丁不足等问题。建议升级到Ubuntu 18.04(Bionic)或更高版本:
- 修改Dockerfile基础镜像为
ubuntu:bionic(或更高版本,如ubuntu:20.04) - 新版本官方源中包含
libu2f-udev,无需额外配置即可正常安装Chrome - 可根据新版本环境调整依赖安装(比如
libgconf-2-4在高版本中可能不再需要)
内容的提问来源于stack exchange,提问作者AJwr
相关产品推荐
相关产品推荐

