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:
/opt/local/bin:/opt/local/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
/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/opt/local/bin:
/opt/local/sbin:/opt/android-sdk/tools/:/opt/android-sdk/platform-tools/
My local build of Emacs is in /usr/local/bin
. I just built and installed it:
$ which emacs
/usr/local/bin/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?
Best Answer
In order to amend your PATH so that
/usr/local/bin
is ahead of/usr/bin
do the following:. ~/.bash_profile
PATH="/usr/local/bin:$PATH"
in the current shellYou 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.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.
/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./sbin
, as distinct from/bin
, is for system management programs (not normally used by ordinary users) needed before/usr
is mounted./usr/bin
is for distribution-managed normal user programs.There is a
/usr/sbin
with the same relationship to/usr/bin
as/sbin
has to/bin
./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./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.