A sample MacOS Bash startup file (.bash_profile)

In case you need a sample .bash_profile startup file for your MacOS or other Unix/Linux system, I thought I’d share my most recent version here.

If you're not familiar with a .bash_profile file, this is a startup file that is read whenever you open a new Terminal window. It's a special configuration file, and it needs to be placed in your home directory. For instance, on my MacBook Pro, this file is located as /Users/al/.bash_profile.

My example bash_profile file

As you can see from my sample file shown below, the.bash_profile file can contain any legal Unix command, including Unix alias  definitions, Unix export and PATH statements, and other commands to set up your Bash prompt (the PS1 syntax shown below).

With that brief introduction, here are the contents of my current Mac bash_profile file:

# aliases
alias cd..="cd .."
alias l="ls -al"
alias lp="ls -p"
alias h=history

# the "kp" alias ("que pasa"), in honor of tony p.
alias kp="ps auxwww"

alias ss="/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background &"

# ant/java stuff
alias ant=/opt/local/bin/ant
export HOSTNAME=alsMac
export ANT_HOST_NAME=alsMac
export ANT_HOME=/opt/local/share/java/apache-ant
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0
export TOMCAT_HOME=/Users/al/tomcat-6.0.16

# jruby
export JRUBY_HOME=/Users/al/Apps/jruby-0.9.2

# maven 2.0.8 config
export M2_HOME=/Users/al/Local/maven-2.0.8
export M2=${M2_HOME}/bin

# general path munging

# postgres
export PATH=${PATH}:/usr/local/pgsql/bin
export PGDATA=/usr/local/pgsql/data

# configure my multi-line prompt
==> '

# X11 #
export DISPLAY=:0.0

If you’re familiar with Unix and Linux systems, these commands probably all look familiar. In my case they are just commands that help set up my Java, Ant, Ruby, Maven, and JRuby environments. That way, each time I open a new Terminal window, everything is set up and ready to go for me.

My Bash prompt definition

In case that Bash prompt (PS1) definition looks a little weird to you, I should mention that I use a multi-line prompt that looks like this:

==> _

The first line of my prompt is actually an empty line, followed by the full path of the current directory on the second line, and the prompt symbol "==>" on the third line.