The yamlfmt is a command-line utility designed to automatically format YAML files according to consistent style rules. It helps standardize indentation, spacing, and document layout, making configuration files easier to read and maintain. This tutorial explains how to install yamlfmt on Ubuntu 26.04.
Install yamlfmt
Retrieve the latest release version from the GitHub repository and store it in a variable:
YAMLFMT_VERSION=$(curl -s "https://api.github.com/repos/google/yamlfmt/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Download the archive and extract the yamlfmt executable into /usr/local/bin:
curl -sSL https://github.com/google/yamlfmt/releases/latest/download/yamlfmt_${YAMLFMT_VERSION}_Linux_x86_64.tar.gz \
| sudo tar xz -C /usr/local/bin yamlfmt
Verify that the installation completed successfully by checking the yamlfmt version:
yamlfmt --version
Testing yamlfmt
Create a sample YAML file for testing:
nano test.yaml
Insert the following content:
foo: bar
list:
- a
- b
- c
nested:
x: 1
y: 2
Run yamlfmt against the file:
yamlfmt test.yaml
The test.yaml file will be formatted in place and its contents will be updated to:
foo: bar
list:
- a
- b
- c
nested:
x: 1
y: 2
Uninstall yamlfmt
If the yamlfmt is no longer required, delete the installed executable from the system:
sudo rm -rf /usr/local/bin/yamlfmt
Leave a Comment
Cancel reply