Getting started with Haxe

John Gabriele

2020-05

This doc is a guide to installing and setting up the latest version of Haxe onto Debian GNU/Linux (the “Testing” distribution).

Install

We’ll install the newest Haxe binary release into ~/opt, and create a couple of symlinks in ~/bin.

If you don’t already have a ~/bin directory, you’ll need to create one, and then make sure it’s on your PATH.

Go to the Haxe Download page and download the Linux 64-bit binaries. Unpack and install like so:

mv path/to/haxe-4.n.m-linux64.tar.gz ~/opt
cd ~/opt
tar xzf haxe-4.n.m-linux64.tar.gz
# Note, that archive unpacks into a directly named like
# haxe_YYYYMMDDhhmmss_xxxxxxx. Rename it to something
# more human-readable:
mv haxe_201xxxxxxxxxxx_xxxxxxx haxe-4.n.m
ln -s haxe-4.n.m haxe
cd ~/bin
ln -s ~/opt/haxe/haxe .
ln -s ~/opt/haxe/haxelib .

Then, so haxe can find its std library, into your ~/.bashrc add:

export HAXE_STD_PATH="$HOME/opt/haxe/std"

Finally, set up haxelib (the library installer tool):

haxelib setup

When prompted for the directory within which haxelib will store installed library files, rather than the default, I specify ~/haxelib. (This directory name will be stored in the ~/.haxelib file.)

If you don’t already have it installed, you’ll need to apt install neko, as haxelib requires it.

Upgrading

To upgrade to a newer release candidate:

  1. As described above: download and unpack the newer Haxe release into ~/opt, and rename the resulting directory to a more human-readable name (like “haxe-4.n.m”).
  2. Still in ~/opt, rm the “haxe” symlink and make a new one pointing to the newly unpacked & renamed haxe-4.n.m directory.

Switching Between Installed Versions

You can at any time easily switch between versions of Haxe in your ~/opt; just rm that symlink named “haxe” and make a new one pointing to a different “haxe-4.n.m” directory.

Check Installation

$ which haxe haxelib
/home/YOU/bin/haxe
/home/YOU/bin/haxelib

$ haxe --version
4.n.m

$ haxelib version
4.n.m  # possibly different from what `haxe` reports

Try it out

Try Haxe out on some code. cd path/to/my-proj. Create a src/Main.hx file containing:

class Main {
    public static function main() {
        trace("Hello, World!");
    }
}

And an interp.hxml build file containing:

-p src
-m Main
--interp

Run your program (this is using Haxe’s built-in interpreter):

haxe interp.hxml

getting this output:

Main.hx:3: Hello, World!

Woo!