How to add a directory to the Bash $PATH

This is a short and simple tip, but something I thought was worth remembering. I like to store my scripts in my ~/bin directory, keeping them all neat and organized. Rather than linking them to my /usr/local/bin directory or typing ~/bin/command-name, I prefer to simply add ~/bin to my Bash path, allowing me to type command-name. Some Linux distros do this for you, but some don't, so here is how to do it.

Simply create/edit the ~/.profile file and add the lines:

if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

You can add other directories here, too. It simply checks that the directory exists and, if it does, adds it to the $PATH variable. After relogging, you will see that you can now run commands in that directory as if it was linked to the /usr/local/bin directory. Bash will automatically read this file every time you log on, so there are no other changes to make!

Sunday 11th October 2009 at 12:06 a.m.
Tagged under: Linux

Comments

Offline Santos34Louise
Joined: 26th Dec 2011
Posts: 0
Posted on Monday 26th December 2011 at 1:03 a.m.

I took my first <a href="http://goodfinance-blog.com/topics/business-loans">business loans</a> when I was a teenager and it aided my business a lot. But, I need the consolidation loans again.


You must be logged in to post a comment.