Getting started with Haxe

John Gabriele

2019-07

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 binary release into ~/opt, and create a couple of symlinks in ~/bin. Go to the Haxe Download page and click the “(View all versions)” link at the top. Then go to newest/topmost “4.0.0-rc.X” and download the Linux 64-bit binaries. Install the binaries like so:

mv path/to/haxe-4.0.0-rc.X-linux64.tar.gz ~/opt
cd ~/opt
tar xzf haxe-4.0.0-rc.X-linux64.tar.gz
# Note, that archive unpacks into a directly named like
# haxe_YYYYMMDDhhmmss_xxxxxxx. Let's rename it to something
# more human-readable:
mv haxe_201xxxxxxxxxxx_xxxxxxx haxe-4.0.0-rc.X
ln -s haxe-4.0.0-rc.X 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

accepting the default ~/haxelib directory name (where haxelib will store installed library files).

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 (ex., to “haxe-4.0.0-rc.X”).
  2. Still in ~/opt, rm the “haxe” symlink and make a new one pointing to the newly unpacked & renamed haxe-4.0.0-rc.X 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.0.0-rc.X” directory.

Check Installation

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

$ haxe --version
4.0.0-rc.X+xxxxxxx

$ haxelib version
3.4.0

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!