Install Wasmtime on Ubuntu 26.04

Install Wasmtime on Ubuntu 26.04

Wasmtime is a fast, secure, and open-source WebAssembly (Wasm) runtime. It is developed by the Bytecode Alliance and designed for running WebAssembly outside the browser in a standards-compliant way. This tutorial shows how to install Wasmtime on Ubuntu 26.04.

Install Wasmtime

Retrieve the latest release version from the official GitHub repository:

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

Download the corresponding Linux archive:

curl -sSLo wasmtime.tar.xz https://github.com/bytecodealliance/wasmtime/releases/latest/download/wasmtime-v$WASMTIME_VERSION-x86_64-linux.tar.xz

Prepare a temporary directory and unpack the archive:

mkdir wasmtime-temp
tar xf wasmtime.tar.xz --strip-components=1 -C wasmtime-temp

Move the executable into a system-wide directory:

sudo mv wasmtime-temp/wasmtime /usr/local/bin

Confirm installation by checking the Wasmtime version:

wasmtime --version

Cleanup of temporary files:

rm -rf wasmtime.tar.xz wasmtime-temp

Testing Wasmtime

A simple WebAssembly Text (WAT) example can be created to validate runtime functionality. Create a sample file:

nano hello.wat

Insert the following module:

(module
  (import "wasi_snapshot_preview1" "fd_write"
    (func $fd_write (param i32 i32 i32 i32) (result i32)))

  (memory (export "memory") 1)
  (data (i32.const 8) "Hello world\n")

  (func (export "_start")
    (i32.store (i32.const 0) (i32.const 8))   ;; iovec.buf  = 8
    (i32.store (i32.const 4) (i32.const 14))  ;; iovec.len  = 14
    (drop (call $fd_write (i32.const 1) (i32.const 0) (i32.const 1) (i32.const 20)))
  )
)

Run the module using Wasmtime:

wasmtime hello.wat

Expected output:

Hello world

Uninstall Wasmtime

To completely remove Wasmtime, delete the binary:

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

Delete the cached runtime data:

rm -rf ~/.cache/wasmtime

Leave a Comment

Cancel reply

Your email address will not be published.