Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
# Apache Ant 1.8.2
PATH="$PATH:/usr/local/apache-ant-1.8.2/bin"
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).

share|improve this question
    
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
add comment

2 Answers

up vote 5 down vote accepted

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.
share|improve this answer
add comment

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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