9

I have XAMPP installed in OSX, and by default it prepends the path to its own bin directory (full of various utilities) to my $PATH variable:

# Add path to XAMPP PHP version
export XAMPP_PHP=/Applications/XAMPP/xamppfiles/bin
export PATH="$XAMPP_PHP:$PATH"

Rather unfortunately, one of its utilities is called HEAD, which thanks to OSX's case-insensitive filesystem, collides with the Unix head command. XAMPP's HEAD is completely unrelated to head (I think it issues an HTTP HEAD request).

Of course, I want to use both head and XAMPP, so I simply changed the path variable order:

export PATH="$PATH:$XAMPP_PHP"

This lets me use head, but now there is a collision between XAMPP's version of PHP (for example, 5.5), and the preinstalled version of PHP that comes with OSX (5.3). Since the path to 5.3 comes first, it ends up taking precedence.

My plan for a hackish solution was to prepend the full file path+name just XAMPP's version of PHP, then append the rest of the path after $PATH:

export PATH="/Applications/XAMPP/xamppfiles/bin/php:$PATH:$XAMPP_PHP"

This does not seem to work. When I restart bash and check php -v, it's still on PHP 5.3 - the built-in version. Is it even possible to add a specific file path to $PATH at all?

  • 4
    No, $PATH may consist only of directories. You could simply symlink the particular executable you want into an existing directory in your $PATH. – larsks Apr 15 '16 at 0:59
8

Assuming that echo "$PATH" shows /usr/local/bin in your path, and given that this is your personal laptop:

Create a symlink in /usr/local/bin that points to the executable you want.

ln -s /Applications/XAMPP/xamppfiles/bin/php /usr/local/bin/php

If it is a shared computer and you don't want to affect other users, I recommend setting up a custom extension to your PATH in ~/.bash_profile. I have one myself:

$ grep PATH ~/.bash_profile 
export PATH="$PATH:$HOME/.bin"

Then I can put my custom symlinks, scripts, etc. in ~/.bin and they will run as expected (without overriding system commands that exist earlier in my PATH).

I put the . at the start of .bin so I don't have to see the directory when browsing in Finder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.