Building Haxe on Ubuntu / Debian

Debian / Ubuntu


The Haxe compiler is written in the OCaml language. Therefore we have to install Ocaml first. Additionally we make sure to have the most important tools and libraries installed.
sudo apt-get install ocaml camlp4 ocaml-findlib cvs zlib1g-dev make wget tar git subversion

Make sure to uninstall existing versions of Haxe which you may have previously installed via .deb packages or manually.

sudo apt-get remove haxe

sudo rm -rf /usr/lib/haxe
sudo rm -rf /usr/bin/haxe*


You can use the following shell script which handles the complete process. It will download the haxe source, build haxe and install it.

installation script:

# Build the haxe compiler
# =====================
# - download '' and execute it (compiles the haxe compiler)
# - copy the executables and modifies the evironment variables

# My libz was in a different place, maybe uncommenting helps
# sudo ln -s /usr/lib/i386-linux-gnu/ /usr/lib/

mkdir haxesrc
cd haxesrc


# reset previous installations
sudo rm -rf /usr/local/haxe
sudo rm -rf /usr/local/bin/haxe*

# install haxe in /usr/local
sudo mkdir /usr/local/haxe
sudo mkdir /usr/local/haxe/bin
sudo cp bin/* /usr/local/haxe/bin
sudo cp -r haxe/std /usr/local/haxe
sudo ln -s /usr/local/haxe/bin/haxe /usr/local/bin/haxe

# setup environment variables for haxe
grep "HAXE_LIBRARY_PATH" /etc/environment || echo "export HAXE_LIBRARY_PATH=/usr/local/haxe/std:." | sudo tee -a /etc/environment
  • Since Haxe3 r6354 HAXE_LIBRARY_PATH is named HAXE_STD_PATH

1. copy the contents of the installation script into a shell script, like


2. make it executable:
chmod +x

3. run it:

Environment variables

The following two variables should be defined in the etc/profile file:


Please make sure that the haxe compiler finds its libraries (the std folder) by correctly setting this environment variable.


Additionaly it doesn't hurt to define the location of your Haxe installation.
# in /etc/profile
# ...
export HAXE_LIBRARY_PATH=/usr/local/haxe/std:. # the ':.' part is important
export HAXE_HOME=/usr/local/haxe
  • Since Haxe3 r6354 HAXE_LIBRARY_PATH is named HAXE_STD_PATH

Final function test

Please run this little test to see if Haxe is able to compile your code.

File Test.hx :

class Test { 
    static function main() { 
        trace("Hello World !"); 

File compile.hxml :

-js test.js
-main Test

Run from command line:

 haxe compile.hxml 

File index.html :
Html code for testing the JavaScript:

        <title>Haxe JS</title>
        <div id="haxe:trace"></div>
        <script type="text/javascript" src="test.js"></script>

version #20086, modified 2014-04-24 20:10:38 by mechagk