I'm working on Mac OS X which is shipped with several binaries mostly located in /usr/bin/ and /usr/sbin/. Since it doesn't have a native package manager like some Linux distros, I got used to managing my own binaries, building and installing in /usr/local/<package_name>/.

This way, I am able to fully remove a package from my system at the cost of manually update the PATH and the MANPATH variables in the .bashrc file.

Here is a simple example:

Mac OS X ships with ant 1.7.0, located in /usr/bin. I need to use the latest version, so I download it from Apache and then unzip (build) it to /usr/local/apache-ant-1.8.2. Then I update my .bashrc file with:

# Mac OS X original PATH
# Apache Ant 1.8.2
export PATH

I make sure to export the /usr/bin/ and /usr/sbin/ before the ant/bin/ because there are often other binaries besides the ant that I don't want to override.

The problem is that when I type which ant I get /usr/bin/. So I rename the /usr/bin/ant to /usr/bin/ant-old in order to work with the latest build.

While this works, I want to know if there are better approaches to replacing a system binary (mainly to avoid the last rename).

  • Do you know about MacPorts and Fink? If not, look them up -- they're 3rd party package managers for OS X and might be of interest to you. – Jeff Apr 18 '11 at 21:17

Replacing a system binary should be a last resort.

My advice is to:

  • Put /usr/local/bin ahead of /usr/bin and other system directories on the PATH.
  • Make /usr/local/bin/ant a symbolic link to /usr/local/apache-ant-1.8.2/bin/ant.
  • Don't include /usr/local/apache-ant-1.8.2/bin in the PATH at all.

This way:

  • Your customizations (in /usr/local/bin) override the system defaults.
  • The symbolic link /usr/local/bin/ant reminds you where you got that version of ant.
  • If you want to test something with the default setup, just remove /usr/local/bin from your PATH for the duration of the test.
|improve this answer|||||

The usual method of overriding system binaries is to install the new binaries in /usr/local/bin (or sbin) and then making sure that /usr/local/bin comes before /usr/bin in your path.

Normally, you do that by configuring packages with --prefix=/usr/local, which causes them to install their binaries under /usr/local/bin, instead of making a directory in /usr/local for each package.

Are you saying there are binaries in /usr/local/apache-ant-1.8.2/bin that you don't want to use? In that case, I'd recommend installing it under /usr/local/apache-ant-1.8.2 (as you're doing now), but then making a symlink in /usr/local/bin to ../apache-ant-1.8.2/bin/ant (instead of putting /usr/local/apache-ant-1.8.2/bin in your path).

|improve this answer|||||

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.