In this article, I will take you through the steps to install yq command line tool on Linux. yq is a free, open source, lightweight and portable command-line YAML, JSON and XML processor written in GO language. It uses jq like syntax but works with yaml files as well as json, xml, properties, csv and tsv. It doesn't yet support everything jq does but it does support the most common operations and functions, and more is being added continuously. We will see the steps to download and install this utility on Linux systems in great detail.
How to Install yq command line tool on Linux in 5 Easy Steps
Step 1: Prerequisites
a) You should have a running Linux Server.
b) You should have
root access to run privileged commands.
c) You should have
wget utility installed in your System.
Step 2: Update Your Server
In the first step, you need to update your System by using package managers like apt, apt-get, yum or dnf depending on the Linux system you are currently using.
a) Using apt-get
If you are using any Debian/Ubuntu based systems, then you can run
sudo apt-get update command to sync the package cache with all the latest available updates from all the enabled Repo.
cyberithub@ubuntu:~$ sudo apt-get update Get:1 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B] Hit:2 http://in.archive.ubuntu.com/ubuntu focal InRelease Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Get:4 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,096 B] Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:6 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [481 kB] Get:7 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,042 kB] Get:9 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1,673 kB] Get:10 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [282 kB] Get:11 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB] Get:12 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [10.8 kB] Get:13 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [714 kB] Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [707 kB] Get:15 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages [559 kB] Get:16 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [365 kB] Get:17 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [130 kB] .........................................
b) Using yum or dnf
If you are using RHEL/CentOS/Fedora/Rocky Linux based systems then you can either use
sudo yum update or
sudo dnf update to sync your package cache with all the latest available updates from the Repo.
[cyberithub@centos8 ~]$ sudo dnf update CentOS Linux 8 - AppStream 6.1 MB/s | 8.4 MB 00:01 CentOS Linux 8 - BaseOS 4.9 MB/s | 4.6 MB 00:00 CentOS Linux 8 - Extras 12 kB/s | 1.5 kB 00:00 Dependencies resolved. Nothing to do. Complete!
Step 3: Install yq
There are multiple ways to install yq command line tool on Linux based systems. Here we will see two best ways to install this utility in our System.
a) Using snap
If you are looking to install
yq as a snap package then you need to use
sudo snap install yq command as shown below.
cyberithub@ubuntu:~$ sudo snap install yq yq 4.26.1 from Mike Farah (mikefarah) installed
b) Using wget
If you are looking to download and install the
yq binary directly from the GitHub then you can use below
wget command to directly download it under
cyberithub@ubuntu:~$ sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
Once downloaded, you need to provide execute permission to run the tool as command.
cyberithub@ubuntu:~$ sudo chmod a+x /usr/local/bin/yq
Step 4: Check Version
You can test the working of the command line tool by running
yq --version command as shown below. If the output shows the current
yq version like below then it is installed correctly. You can proceed with its usage.
cyberithub@ubuntu:~$ yq --version yq (https://github.com/mikefarah/yq/) version 4.26.1
Step 5: Uninstall yq
Once you are done with the yq utility, you can also think of removing it from your system by using below two methods depending on how you installed it.
a) Using snap
If you have installed the utility as a snap then you can remove it by using sudo
snap remove yq command as shown below.
cyberithub@ubuntu:~$ sudo snap remove yq yq removed
b) Using Manual Removal
If you have just downloaded and copy the binary file in
/usr/local/bin/ directory using wget or curl then you can simply remove the binary file by using
sudo rm -rf /usr/local/bin/yq command as shown below.
cyberithub@ubuntu:~$ sudo rm -rf /usr/local/bin/yq