Skip to main content

Quick start on Linux

In this guide, we will walk you through how to quickly install and run the WasmEdge Runtime on a generic Linux distribution (such as Ubuntu, Debian, Raspberry OS or WSL on Windows). Comprehensive and OS-specific installation instructions can be found here.

note

If you have Docker Desktop 4.15 and above, you can skip this and get started here. For Fedora Linux / Red Hat Linux / OpenShift / Podman users, get started here.

We will cover the following examples:

One-liner Installation of WasmEdge

The easiest way to install WasmEdge is to run the following command. You should have root or at least sudo privilege. Your system should have git and curl installed as prerequisites.

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- -p /usr/local

If you do not have root or sudo rights, use the following line to install WasmEdge in your $HOME/.wasmedge directory:

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash

How to run a standalone WASM app

The Hello world example is a standalone Rust application that can be executed by the WasmEdge CLI. Its source code and build instructions are available here.

Download the hello.wasm file here, or run the following command:

wget https://github.com/second-state/rust-examples/releases/latest/download/hello.wasm

Use the wasmedge command to run the program.

$ wasmedge hello.wasm
Hello WasmEdge!

Use the AoT compiler wasmedgec to get much better performance.

$ wasmedgec hello.wasm hello_aot.wasm
$ wasmedge hello_aot.wasm
Hello WasmEdge!

To learn more about how to create WASM apps in Rust

How to run an HTTP server

This example is a standalone HTTP server written in Rust. It demonstrates that Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available here.

Download the server.wasm file here, or run the following command:

wget https://github.com/second-state/rust-examples/releases/latest/download/server.wasm

Use the wasmedge command to run the program.

$ wasmedge server.wasm
Listening on http://0.0.0.0:8080

From another terminal window, do the following.

$ curl http://localhost:8080/
Try POSTing data to /echo such as: `curl localhost:8080/echo -XPOST -d 'hello world'`

$ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge"
Hello WasmEdge

To learn more about how to create WASM services in Rust

How to run a JavaScript-based server

This example is a standalone HTTP server written in JavaScript using the node.js API. It demonstrates WasmEdge as a lightweight runtime for node.js applications. Its source code is available here.

  • Download the wasmedge_quickjs.wasm file here, or run the following command:
wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm
  • Download the modules.zip file here, or run the following command:
wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip

Unzip the modules.zip file into the current folder as ./modules/.

unzip modules.zip
  • Download the server.js file here.
wget https://raw.githubusercontent.com/second-state/wasmedge-quickjs/main/example_js/docker_wasm/server/server.js

Use the wasmedge command to run the program.

$ wasmedge --dir .:. wasmedge_quickjs.wasm server.js
listen 8080 ...

From another terminal window, do the following.

$ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge"
Hello WasmEdge

To learn more about how to run JavaScript apps in WasmEdge.

Next steps