I have the following in my .bash_profile:

$ cat ~/.bash_profile 
# Prompt
export PS1="\h:\W$ "

# Standard path
export PATH="/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:

# Android
export ANDROID_NDK_ROOT=/opt/android-ndk
export ANDROID_SDK_ROOT=/opt/android-sdk
export JAVA_HOME=`/usr/libexec/java_home`
export ANDROID_HOME="$HOME/.android"

export PATH="$PATH:$ANDROID_SDK_ROOT/tools/":"$ANDROID_SDK_ROOT/platform-tools/"

I verified the path with:

$ echo $PATH

My local build of Emacs is in /usr/local/bin. I just built and installed it:

$ which emacs

When I run Emacs, I get the one from /usr/bin:

$ emacs --version
GNU Emacs 22.1.1
$ /usr/bin/emacs --version
GNU Emacs 22.1.1
$ /usr/local/bin/emacs --version
GNU Emacs 24.5.1

Why am I having trouble with the paths? Why is OS X ignoring them? How can I use my copy of Emacs in /usr/local/bin/emacs without specifying the full path?

  • If you open a new terminal tab, does the problem persist there? – nohillside Feb 4 '16 at 5:43

In order to amend your PATH so that /usr/local/bin is ahead of /usr/bin do the following:

  1. execute . ~/.bash_profile
  2. execute PATH="/usr/local/bin:$PATH" in the current shell
  3. restart Terminal

You may also want to amend /etc/paths so that /usr/local/bin is listed before /usr/bin. You'll need to sudo your editor in order to do that.

sudo open -t /etc/paths

Bear in mind that if you edit /etc/paths there is a risk that non-terminal applications may pick up your locally build version. Just FYI.

A little more information on paths.

  1. /bin (and /sbin) were intended for programs that needed to be on a small / partition before the larger /usr, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh, although the original intent may still be relevant for e.g. installations on small embedded devices.

  2. /sbin, as distinct from /bin, is for system management programs (not normally used by ordinary users) needed before /usr is mounted.

  3. /usr/bin is for distribution-managed normal user programs.

  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin.

  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.

  6. /usr/local/sbin, as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin.

This source helps explain the filesystem hierarchy standard on a deeper level.

And you might find this article on the use and abuse of /usr/local/bin interesting as well.

  • The OP already had /usr/local/bin at the beginning of PATH… – nohillside Feb 4 '16 at 5:42
  • Yes, thank you, I have noticed that too. One may (or may not) wish to omit according command at will. BTW, who is OP? :) – Denis Rasulev Feb 4 '16 at 5:45
  • Original Poster :-) BTW, I didn't even realize that people go into holy wars over the use of /usr/local. – nohillside Feb 4 '16 at 5:57

I found I had to reboot the machine to have the changes take effect. A logoff/logon may have had the same effect, but I did not try it.

  • If you had cleared the hash table then the new emacs would have been called. No need tp logout or reboot. – fd0 Jun 12 '17 at 10:00
  • @fd0 - Forgive my ignorance... What hash table are you talking about? What does it have to do with a path or a program? – user83961 Jun 12 '17 at 10:44
  • The hash table is a shell feature that records the full path of a command to memory after a PATH lookup. Subsequent calls to a command are first checked in the hash table instead of having to use a PATH lookup. More info can be found with the command help hash. – fd0 Jun 12 '17 at 12:00

You must log in to answer this question.