How to Apt-Get Install in a GitHub Actions Workflow

How to Apt-Get Install in a GitHub Actions Workflow

In today’s post, we’re going to learn how to utilize the apt-get command in a GitHub Actions workflow. This is a critical aspect of workflows that are run on Ubuntu runners, as you may need to install certain software packages to execute your jobs. If you’re familiar with Ubuntu or other Debian-based Linux distributions, you’ve likely encountered the apt-get command before.

What is Apt-Get?

First, let’s go over some basics. apt-get is a package handling utility for Debian-based systems. It handles packages and manages their retrieval, configuration, and installation. It can automatically install packages along with their dependencies.

Utilizing Apt-Get in GitHub Actions

In GitHub Actions, you can use the apt-get command inside a run step in your workflow. GitHub provides Linux virtual machines ubuntu-latest, ubuntu-20.04, and ubuntu-18.04 as runners for your jobs. These runners have a number of preinstalled packages, but there are instances when you might need additional software.

Here is a step-by-step guide:

Let’s dissect the steps:

  1. name: Apt-get example: This is the name of our workflow. You can replace “Apt-get example” with any name you prefer.
  2. on: [push]: This specifies that the workflow will run on any push event.
  3. jobs:: Here we define our jobs. In this case, we have only one job named build.
  4. runs-on: ubuntu-latest: This specifies that our job will run on the latest version of Ubuntu.
  5. steps:: This is where we define the steps that our job will run.
  6. - name: Checkout code: This is our first step. We are using the actions/checkout@v2 action to checkout our code.
  7. - name: Install Dependencies: This is our second step where we install dependencies.
  8. run: |: The run keyword is followed by a pipe (|), indicating we’ll be running multiple commands.
  9. sudo apt-get update: This command updates the package lists for upgrades and new package installations.
  10. sudo apt-get install -y <package-name>: This command installs the package specified. Replace <package-name> with the name of the package you want to install. The -y flag is used to automatically answer yes to the prompts and run non-interactively.

That’s it! You can now use apt-get to install any software packages you need in your GitHub Actions workflow.

Conclusion

In this blog post, we covered how to use the apt-get command within a GitHub Actions workflow. This is essential when setting up your CI/CD pipeline, as you might need to install additional software not provided by the default GitHub Actions runners.