Where do you keep your own scripts on OSX? [closed]
As I write my bash scripts for my OS X that do general things, I am wondering where is a good place to keep them. Is there a directory I can put them all in where they will be picked up automatically? Or should I create my own directory and then reference this directory from .profile or something?
Usually /usr/local/bin
, unless you don't want other users to have access to them, in which case $HOME/bin
.
/usr/local/bin
may be in the default PATH, but $HOME/bin
will certainly need to be added to PATH.
Adding
$HOME/bin
to PATH:
PATH=${PATH}:$HOME/bin
export PATH
I have my PATH set as:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
$HOME/bin
I use /usr/local/bin
for commands that I have that override the default commands. For example, I have Subversion 1.7.7 installed, and the OS X comes with 1.6.18. The version 1.7.7 of svn
is in /usr/local/bin
while the default 1.6.18 version of svn
is in /usr/bin
. When I type svn
, I get the version I installed instead of the version that comes with OS X. I've done this with Java, Git, Python, and several other binaries where I need a different version that what came on my Mac. Most of these are symbolic links. For example:
$ ls -l /usr/local/bin/ant
lrwxr-xr-x 1 root wheel 16 Jun 12 11:01 ant -> /opt/ant/bin/ant
Ant 1.9.1 is installed in /opt/ant
(actually, /opt/apache-ant-1.9.1
, but it's symbolically linked to /opt/ant
). I linked all the stuff under /opt/ant/bin
to /usr/local/bin
, so it's in my path.
I use $HOME/bin
for my personal shell scripts and other scripts. Traditionally, you make this the last entry in your PATH, so you don't accidentally override a built in command. If I made a shell script command called cp
, I wouldn't override the /bin/cp
command.