首页 > 解决方案 > 如何在 GitHub Actions 工作流程中进行 apt-get install?

问题描述

在新的 GitHub Actions 中,我正在尝试安装一个包,以便在后续步骤之一中使用它。

name: CI

on: [push, pull_request]

jobs:
  translations:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
      with:
        fetch-depth: 1
    - name: Install xmllint
      run: apt-get install libxml2-utils
    # ...

然而,这失败了

Run apt-get install libxml2-utils
  apt-get install libxml2-utils
  shell: /bin/bash -e {0}
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
##[error]Process completed with exit code 100.

最好的方法是什么?我需要接触 Docker 吗?

标签: github-actions

解决方案


文档说:

Linux 和 macOS 虚拟机都使用无密码运行sudo。当您需要执行命令或安装需要比当前用户更多权限的工具时,您sudo无需提供密码即可使用。

因此,只需执行以下操作即可:

- name: Install xmllint
  run: sudo apt-get install -y libxml2-utils

推荐阅读