Install WABT on Ubuntu 24.04

Install WABT on Ubuntu 24.04

WebAssembly Binary Toolkit (WABT) is a collection of command line utilities for working with WebAssembly files. It includes tools for converting between WebAssembly binary format (wasm) and its text format (wat), decompiling binaries into a readable pseudocode form, and other debugging or inspection tasks. This tutorial explains how to install WABT on Ubuntu 24.04.

Install WABT

First, query the GitHub API to fetch the most recent WABT version number:

WABT_VERSION=$(curl -s "https://api.github.com/repos/WebAssembly/wabt/releases/latest" | grep -Po '"tag_name": "\K[0-9.]+')

Then download the corresponding archive with prebuilt binaries:

wget -qO wabt.tar.gz https://github.com/WebAssembly/wabt/releases/latest/download/wabt-$WABT_VERSION-ubuntu-20.04.tar.gz

Create WABT installation directory and unpack the archive there:

sudo mkdir /opt/wabt
sudo tar xf wabt.tar.gz --strip-components=1 -C /opt/wabt

Make WABT binaries available system-wide by adding its bin directory to the PATH environment variable:

echo 'export PATH=$PATH:/opt/wabt/bin' | sudo tee -a /etc/profile.d/wabt.sh

To make the changes take effect immediately, either log out and sign back in, or run the command below:

source /etc/profile

You can verify that the toolkit is set up correctly by checking the versions of its key commands:

wat2wasm --version
wasm2wat --version

Once installed, the tar.gz file is no longer needed, remove it:

rm -rf wabt.tar.gz

Testing WABT

Let's test WABT by compiling a small WebAssembly text file. Create a sample wat file:

nano add.wat

Paste the following WebAssembly text format code:

(module
  (func (export "add") (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add))

Convert WebAssembly text format to its binary format:

wat2wasm add.wat -o add.wasm

Now decompile wasm binary into readable C-like syntax:

wasm-decompile add.wasm

Output:

export function add(a:int, b:int):int { // func0
  return a + b
}

Uninstall WABT

If you no longer need WABT, remove its installation directory:

sudo rm -rf /opt/wabt

Remove the environment configuration script:

sudo rm -rf /etc/profile.d/wabt.sh

Leave a Comment

Cancel reply

Your email address will not be published.