I’m learning me some cocos2d-x at the moment, and one of the things they ask you to do is to add a couple of PATH variables for convenience, such as the following:
- NDK_ROOT – A reference to where the Android Native Development Kit lives on your system
- SDK_ROOT – A reference to where the Android SDK lives on your system
- ANT_ROOT – A reference to Apache ANT (A Java based build tool, kind of similar to ‘make’)
Usually the way you do this in a Linux/Unix terminal is to run the following command (For example, with NDK_ROOT)
The problem I found with OSX was that it would only save the NDK_ROOT variable for the current Terminal session. When opening a new terminal window, the variables would be lost. Very frustrating.
I found out that the reason is that Unix has two types of shells. A login shell (When you’re already in a desktop environment or logged in via SSH) and a non-login shell (Imagine in the good old days where you login via a green-text-on-black screen terminal).
Login shells execute .bash_profile before you start typing commands, and non-login shells execute .bashrc first.
When you run the above command, the PATH variable is saved to .bashrc, not .bash_profile.
Now, the problem is that OSX creates a new login shell every time you open Terminal and subsequent tabs, which executes .bash_profile, missing out on the PATH variables we saved in .bashrc. Thus, any PATH variables saved in a Terminal session will not be loaded the next time Terminal is opened.
The solution according to Josh Staiger is to add some lines to .bash_profile that loads in the PATH variables from .bashrc using to avoid this problem. I did this and it seemed to fix it.
…. I f**king hate Unix. Seriously. I just want to make a game or something.