Build Haxe on Mac OS X

Mac OS X Intel


Installing XCode

Before you begin you have to make sure, that your system has a compiler (gcc) and compiling tools (make, automake,...) installed. You can check this at your Terminal:


If nothing can be found it's time to install the compiler with XCode. Download and install it from here

Installing Macports

Macports is an open source package manager that helps you to compile and install typical GNU/Linux software. Download and install it from here and then open your Terminal.

Installing the required packages with Macports

The Haxe compiler is written in the OCaml language. Therefore we have to install Ocaml first. Additionally we make sure that the most essential tools are installed.

sudo port install ocaml cvs wget subversion


You can use the following shell script for the complete build and install process.

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


2. make it executable:
sudo chmod 0755

3. run it:

installation script:

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

if [ ! -d haxesrc ] 
    then mkdir haxesrc 
cd haxesrc

if [ -f ] 
    then rm 

# reset previous installations
sudo rm -rf /usr/lib/haxe

# install haxe in /usr/lib
sudo mkdir /usr/lib/haxe
sudo cp bin/haxe /usr/lib/haxe/
sudo rsync -av --exclude='*/.svn*' haxe/std /usr/lib/haxe

# setup environment variables for haxe
sudo grep "HAXE_LIBRARY_PATH" ~/.bash_profile || echo "export HAXE_LIBRARY_PATH=/usr/lib/haxe/std:." >> ~/.bash_profile
source ~/.bash_profile

Environment variables

The following two variables should be defined in your ~/.bashrc file:


Please make sure that the haxe compiler finds its libraries by correctly setting up the environment variable in your ~/.bashrc.


Additionally, it doesn't hurt to define the location of your Haxe installation.
# somewhere in your ~/.bashrc
# ...
# the ':.' part after std is important
export HAXE_LIBRARY_PATH=/usr/lib/haxe/std:. 
export HAXE_HOME=/usr/lib/haxe

To initialize the variables you have to call your ~/.bashrc file:

source ~/.bashrc

It is also a good idea to run:

ls -l `which haxe`

Verify that the haxe binary is now called from /usr/lib/haxe/haxe (or wherever you specified), and that the date created is today.

Final function test

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

File Test.hx

class Test{
    public static function main(){
        trace('hello world!');

File compile.hxml:

-main Test
-x Test

Compile it:

 haxe compile.hxml 


In case you get the following error:
Standard library not found

make sure that your environment variables are correct:


You should get something like

then check if the files are there

$ ls /usr/lib/haxe/std/
 Enum.hx  flash9   IntHash.hx  Lambda.hx ...

Other Information about Building on Mac Intel

Building on Mac Intel requires an Intel build version of OCaml. You can download it from or install it via Macports with port install ocaml.

After a successful build, the Haxe compiler will be in the bin folder.

In case you want to have the final std folder location other than /usr/lib/haxe/std/ you need to change Plugin.class_path in to your preferred location and start over.

Finally, if you wish to update your installation to the newest svn version, simply run the script again. It will update the file, update the svn copies, and reinstall everything.

version #19812, modified 2013-10-10 15:25:57 by vault