132
votes

In the new GitHub Actions, I am trying to install a package in order to use it in one of the next steps.

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
    # ...

However this fails with

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.

What's the best way to do this? Do I need to reach for Docker?

1
sudo apt-get install libxml2-utils - runwuf
The docs say "The Linux and macOS virtual machines both run using passwordless sudo", so simply doing sudo apt-get should work, as @runwuf suggested. - rmunn
@runwuf - Do you want the rep points for your answer? Go ahead and post an answer. I'll post an answer myself so that the question looks like it has an answer in the search list, but if you post an answer, Niklas should accept it and then I'd delete mine. - rmunn
@rmunn no worries, your answer has proper reference and details unlike my one liner :) Cheers! glad it works for you @Niklas! - runwuf

1 Answers

196
votes

The docs say:

The Linux and macOS virtual machines both run using passwordless sudo. When you need to execute commands or install tools that require more privileges than the current user, you can use sudo without needing to provide a password.

So simply doing the following should work:

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