Building Jsonnet from Source
Published on 7 Jul 2019 · Filed in Information · 504 words (estimated 3 minutes to read)I recently decided to start working with jsonnet
, a data templating language and associated command-line interface (CLI) tool for manipulating and/or generating various data formats (like JSON, YAML, or other formats; see the Jsonnet web site for more information). However, I found that there are no prebuilt binaries for jsonnet
(at least, not that I could find), and so I thought I’d share here the process for building jsonnet
from source. It’s not hard or complicated, but hopefully sharing this information will streamline the process for others.
As some readers may already know, my primary OS is Fedora. Thus, the process I share here will be specific to Fedora (and/or CentOS and possibly RHEL).
To keep my Fedora installation clean of any unnecessary packages, I decided to use a CentOS 7 VM—instantiated and managed by Vagrant—for the build process. If you don’t want to use a build VM, you can omit the steps involving Vagrant. You’ll also need to modify the commands used to install the necessary packages (on Fedora, you’d use dnf
instead of yum
, for example). Different distributions may also use different package names for some of the dependencies, so keep that in mind.
-
Run
vagrant up
in a directory with aVagrantfile
configured to instantiate a CentOS 7 VM. The CentOS 7 box I used was the Libvirt-formatted “centos/7” box, version 1902.01. -
Log into the VM using
vagrant ssh
. -
Install the necessary prerequisites with
sudo yum install gcc gcc-c++ git
. -
Clone the GitHub repository for
jsonnet
withgit clone https://github.com/google/jsonnet.git
. This clones the repository into a directory named “jsonnet” in the current directory. -
Switch into the directory for the cloned repository with
cd jsonnet
. -
Run
make
to build Jsonnet. Two binaries will result:jsonnet
andjsonnetfmt
.
At this point, you should have functioning binaries, but they’re inside the CentOS build VM. To get them copied outside the VM, it is a simple matter of just a few quick commands:
-
First, create an SSH configuration file with
vagrant ssh-config > config
. To know the hostname that Vagrant uses for the VM, you cancat config
afterward and look at theHost
line. -
Copy the
jsonnet
binary withscp -F config centos-7:/home/vagrant/jsonnet/jsonnet .
(replacecentos-7
with whatever hostname Vagrant is using for the VM, and adjust the path as needed). -
Copy the
jsonnetfmt
binary withscp -F config centos-7:/home/vagrant/jsonnet/jsonnetfmt .
(replacecentos-7
with whatever hostname Vagrant is using for the VM, and adjust the path as needed).
At this point, you can destroy the VM with vagrant destroy
and then move the binaries into a directory in the PATH.
And that’s it! As I said, the process isn’t hard or difficult, but I did want to share the information nevertheless. Although it didn’t take me long to figure out what dependencies were needed to build the Jsonnet binaries, having them spelled out here may still save someone else some precious time.
Hit me up on Twitter if you find that I missed something in the instructions above, or if you have any questions.