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-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:
name: Apt-get example
- name: Checkout code
- name: Install Dependencies
sudo apt-get update
sudo apt-get install -y
Let’s dissect the steps:
name: Apt-get example: This is the name of our workflow. You can replace “Apt-get example” with any name you prefer.
on: [push]: This specifies that the workflow will run on any push event.
jobs:: Here we define our jobs. In this case, we have only one job named
runs-on: ubuntu-latest: This specifies that our job will run on the latest version of Ubuntu.
steps:: This is where we define the steps that our job will run.
- name: Checkout code: This is our first step. We are using the
actions/checkout@v2action to checkout our code.
- name: Install Dependencies: This is our second step where we install dependencies.
run: |: The
runkeyword is followed by a pipe (
|), indicating we’ll be running multiple commands.
sudo apt-get update: This command updates the package lists for upgrades and new package installations.
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
-yflag 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.
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.