如何在 Debian 类工作站(如 Debian、Ubuntu、Linux Mint、MX Linux、Deepin、AntiX、PureOS、Kali Linux、Parrot OS、Devuan、Knoppix、AV Linux 等)上安装最新版的 Google Chrome Stable?以下是一个完整的指南,涵盖从添加 GPG 密钥、设置 Google 仓库到安装软件的全过程。示例在 Ubuntu 20.04 LTS 上测试通过。

使用 Ansible 在 Debian 类系统中安装 Google Chrome

任务步骤

  1. 添加 Google Chrome 的 GPG 密钥 ⇒ ansible.builtin.apt_key
  2. 添加 Google Chrome 仓库 ⇒ ansible.builtin.apt_repository
  3. 更新 apt 缓存并安装 Google Chrome ⇒ ansible.builtin.apt

详细步骤

  1. 下载仓库的 GPG 签名密钥 使用 ansible.builtin.apt_key 模块。此加密密钥用于验证软件包和仓库的真实性,确保软件与 Google 发布的版本一致。
  2. 将 Google Chrome 仓库添加到系统中 使用 ansible.builtin.apt_repository 模块。这是额外的软件源,系统包管理器(如 apt)会从此处获取软件。
  3. 更新 apt 缓存并安装 Google Chrome 使用 ansible.builtin.apt 模块。

参数说明

  • apt_key
  • url(字符串):仓库 GPG 签名密钥的 URL。
  • state(字符串):present 或 absent,确保密钥存在于系统中。
  • apt_repository
  • repo(字符串):仓库的参数,格式为 deb [arch=amd64] <URL> stable main。
  • state(字符串):present 或 absent,确保仓库存在于系统中。
  • filename(字符串):生成的 .list 文件名,位于 /etc/apt/sources.list.d/ 目录下。
  • apt
  • name(字符串):软件包名称(此处为 Google Chrome)。
  • state(字符串):latest、present 或 absent,确保软件包安装到最新版本。
  • update_cache(布尔值):是否在安装前更新 apt 缓存,确保下载最新版本的软件包。

示例代码

以下是一个 Ansible Playbook,用于在 Debian 类系统中安装 Google Chrome。

文件名:install_chrome_debian.yml

---
- name: 安装 Google Chrome
  hosts: all
  become: true
  tasks:
    - name: 安装 apt-transport-https
      ansible.builtin.apt:
        name: "apt-transport-https"
        state: "latest"
        update_cache: true

    - name: 添加 GPG 签名密钥
      ansible.builtin.apt_key:
        url: "https://dl.google.com/linux/linux_signing_key.pub"
        state: "present"

    - name: 添加 Google Chrome 仓库
      ansible.builtin.apt_repository:
        repo: "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main"
        state: "present"
        filename: "google-chrome"

    - name: 安装 Google Chrome
      ansible.builtin.apt:
        name: "google-chrome-stable"
        state: "latest"
        update_cache: true

执行命令

$ ansible-playbook -i ubuntu/inventory install_chrome_debian.yml

执行结果

PLAY [安装 Google Chrome] *******************************************************

TASK [Gathering Facts] ******************************************************
ok: [ubuntu.example.com]

TASK [安装 apt-transport-https] *********************************************
changed: [ubuntu.example.com]

TASK [添加 GPG 签名密钥] *****************************************************
changed: [ubuntu.example.com]

TASK [添加 Google Chrome 仓库] **********************************************
changed: [ubuntu.example.com]

TASK [安装 Google Chrome] ***************************************************
changed: [ubuntu.example.com]

PLAY RECAP *******************************************************************
ubuntu.example.com         : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

验证安装

$ ssh devops@ubuntu.example.com
$ sudo su -
# apt-cache search google-chrome
google-chrome-beta - The web browser from Google
google-chrome-stable - The web browser from Google
google-chrome-unstable - The web browser from Google

# apt-cache show google-chrome-stable
Package: google-chrome-stable
Version: 94.0.4606.81-1
Architecture: amd64
Maintainer: Chrome Linux Team <chromium-dev@chromium.org>
Installed-Size: 276179
Pre-Depends: dpkg (>= 1.14.0)
Depends: ca-certificates, fonts-liberation, libasound2 (>= 1.0.16), libatk-bridge2.0-0 (>= 2.5.3), libatk1.0-0 (>= 2.2.0), libatspi2.0-0 (>= 2.9.90), libc6 (>= 2.17), libcairo2 (>= 1.6.0), libcups2 (>= 1.6.0), libcurl3-gnutls | libcurl3-nss | libcurl4 | libcurl3, libdbus-1-3 (>= 1.5.12), libdrm2 (>= 2.4.38), libexpat1 (>= 2.0.1), libgbm1 (>= 8.1~0), libgcc1 (>= 1:3.0), libglib2.0-0 (>= 2.39.4), libgtk-3-0 (>= 3.9.10) | libgtk-4-1, libnspr4 (>= 2:4.9-2~), libnss3 (>= 2:3.22), libpango-1.0-0 (>= 1.14.0), libx11-6 (>= 2:1.4.99.1), libxcb1 (>= 1.9.2), libxcomposite1 (>= 1:0.4.4-1), libxdamage1 (>= 1:1.1), libxext6, libxfixes3, libxkbcommon0 (>= 0.4.1), libxrandr2, libxshmfence1, wget, xdg-utils (>= 1.0.2)
Recommends: libu2f-udev, libvulkan1
Provides: www-browser
Priority: optional
Section: web
Filename: pool/main/g/google-chrome-stable/google-chrome-stable_94.0.4606.81-1_amd64.deb
Size: 90229076
SHA256: bfe97cd8d9f941e4a1e73f53d9de6bb54e73a007ee4ce5d4e94a9a65ae2d7fb4
SHA1: 2dc4cbaa205ab61dbf10303400f23e3515fe6c4b
MD5sum: bd49a8b9956cef901657482050a88925
Description: The web browser from Google
 Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.
Description-md5: a2d34067fc33f1c87253c33b9fd975f0

# ls -al /etc/apt/sources.list.d/
total 16
drwxr-xr-x 2 root root 4096 Oct 11 11:42 .
drwxr-xr-x 7 root root 4096 Oct 11 11:42 ..
-rw-r--r-- 1 root root   68 Oct 11 11:40 dl_google_com_linux_chrome_deb.list
-rw-r--r-- 1 root root  189 Oct 11 11:42 google-chrome.list

# cat /etc/apt/sources.list.d/google-chrome.list 
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out this entry, but any other modifications may be lost.
deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

# apt list google-chrome-stable
Listing... Done
google-chrome-stable/stable,now 94.0.4606.81-1 amd64 [installed]

通过以上步骤,您可以在 Debian 类系统中使用 Ansible 的 apt 模块轻松安装 Google Chrome,并确保其来自官方的可信源。