Need help with mruby-cli?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

421 Stars 30 Forks MIT License 112 Commits 19 Opened issues


mruby-cli is a platform to build native command line applications for Linux, Windows, and OS X. It provides the tools necessary for building a standalone binary of your application from any machine. Take advantage of the power of Ruby without the cross-platform dependency headaches that go with it.

Services available


Need anything else?

Contributors list

mruby CLI

A utility for setting up a CLI with mruby that compiles binaries to Linux, OS X, and Windows.


You'll need the following installed and in your


On Mac OS X and Windows, Docker Toolbox is the recommended way to install Docker and docker-compose (does not work on windows).

Building a CLI app

To generate a new mruby CLI, there's a

$ mruby-cli --setup 

This will generate a folder

 containing a basic skeleton for getting started. Once you're in the folder, you can build all the binaries:
$ docker-compose run compile

You'll be able to find the binaries in the following directories:

  • Linux (64-bit):
  • Linux (32-bit):
  • OS X (64-bit):
  • OS X (32-bit):
  • Windows (64-bit):
  • Windows (32-bit):

You should be able to run the respective binary that's native on your platform. There's a

service that can be used as well. In the example below,
mruby-cli --setup hello_world
was run.
$ docker-compose run shell
[email protected]:/home/mruby/code# mruby/build/host/bin/hello_world
Hello World

On Windows system

When running on a windows system

docker-compose run
, you need to add the flag
. For instance,
docker-compose run -d compile
. If you don't add it, you will got the following error:
Please pass the -d flag when using `docker-compose run`.


Each app will be generated with a Dockerfile that inherits a base image.

You can pull the image from docker hub here:

The Dockerfile for the base image is available on github:

Hello World

Building the canonical hello world example in mruby-cli is quite simple. The two files of note from the generate skeleton are

. The CLI hooks into the
method defined here and passes all the arguments as

def __main__(argv)
  puts "Hello World"


The rubygems equivalent is mrbgems. mgem-list contains a list of mgems you can pull from. By default mruby does not include everything in the kitchen sink like MRI. This means to even get

, we need to include the
. The list of core gems can be found here. Adding dependencies is simple, you just need to add a line near the bottom of your
with the two arguments: name and where it comes from.

: ```ruby'helloworld') do |spec| spec.license = 'MIT' = 'Terence Lee' spec.summary = 'Hello World' spec.bins = ['helloworld']

spec.adddependency 'mruby-print', :core => 'mruby-print' spec.adddependency 'mruby-mtest', :mgem => 'mruby-test' end ```

CLI Architecture

The app is built from two parts a C wrapper in

and a mruby part in
. The C wrapper is fairly minimal and executes the
method in mruby and instantiates
and passes it to the mruby code. You won't need to touch the C wrapper. The rest of the CLI is written in mruby. You can't have subfolders in
but you can have as many files in
. All these files are precompiled into mruby bytecode The build tool for mruby is written in CRuby (MRI).


By default,

generates two kinds of tests: mtest and bintest.


These tests are unit tests, are written in mruby, and go in the

directory. It uses the mrbgem
. The available methods to be used can be found here. To run the tests, just execute:
$ docker-compose run mtest


These are integration tests, are written in CRuby (MRI), and go in the

directory. It tests the status and output of the host binary inside a docker container. To run them just execute:
$ docker-compose run bintest


  • mruby-cli
    itself is an app generated by
    , so you can explore this repo on how to build one.
  • mjruby - replacement for jruby-launcher.
  • mruby-eso-research - an app for managing crafting research in Elder Scrolls Online. It uses YAML as the data store.
  • nhk-easy-cli - a command-line client for reading NHK News Web Easy.
  • mruby-static - a static site generator

mruby-cli Development

Compile the mruby-cli binaries

This app is built as a

app. To compile the binaries, you must type
docker-compose run compile

and find the binaries in the appropriate directories (


The docker container contains the necessary cross toolchain to compile a binary for each supported target. That's why it is checked before running a rake task if it is run inside a container.

Indeed, just using

rake compile
will not work out of the box because the main build is designed to compile on a 64-bit Linux host. It could work if you are on a 64-Linux host and you have an cross toolchain equivalent to the one we provide into the docker container.

This means that if you want to add a new rake task

, you need to add it to the
to make it available through
docker-compose run my_task

Create the releases

Just type:

docker-compose run release

After this command finishes, you'll see the releases for each target in the


Create package

We can package the ad hoc release as deb, rpm, msi, or dmg for the following Linux.

To create all the package, just type

docker-compose run package

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.