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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
name: Apt-get example on: [push] jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install Dependencies run: | 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 namedbuild
.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 theactions/checkout@v2
action to checkout our code.- name: Install Dependencies
: This is our second step where we install dependencies.run: |
: Therun
keyword 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-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.