Install yq on Ubuntu 22.04

Install yq on Ubuntu 22.04

The yq is a command line based YAML processor which allows manipulating and extract values from YAML data.

This tutorial demonstrates how to install yq on Ubuntu 22.04.

Install yq

Download the latest executable file of yq from GitHub:

sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64

Set execute permission for file:

sudo chmod a+x /usr/local/bin/yq

Now yq command is available for all users as a system-wide command.

We can check yq version:

yq --version

Testing yq

Create test.yaml file for testing:

printf "status: success\ndata:\n  - name: John\n    age: 25\n  - name: James\n    age: 29" > test.yaml

The yq uses an expression to filter YAML data. Each different part in expression is separated by a dot (.). For example, the following command prints unchanged YAML:

yq e '.' test.yaml

The output of the command:

status: success
data:
  - name: John
    age: 25
  - name: James
    age: 29

We can retrieve a particular value in YAML data as follows:

yq e '.data[1].name' test.yaml

Output:

James

Uninstall yq

If you decided to remove yq, delete executable file:

sudo rm -rf /usr/local/bin/yq

Leave a Comment

Cancel reply

Your email address will not be published.