Saturday, 9 April 2011

Adding to system PATH for all users

I have a few scripts that I use to do certain things on my machines. Rather than copy them to /usr/sbin or similar I like to keep them segregated in a "scripts" directory. In this way I can copy them to new machines or keep them up to date using rsync without messing up the standard scripts that ship with Debian/Ubuntu.

To make the scripts executable for users without typing in the full path to the scripts directory you can edit the users bash profile file ".bashrc" and add the path there. However, this gets messy real fast when dealing with lots of users, so we want a way to update the path for every user that logs in. We do this by putting a script in the /etc/profiles.d directory
Note: Scripts in /etc/profile.d are executed whenever a user logs in to a bash session.

Create a file in /etc/profile.d.
sudo vi /etc/profile.d/

Add this line;


Log out and log in again and check to see if your path has been updated;

echo $PATH