Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

Wednesday, 25 May 2011

Modify The System-Wide PATH

For years, when I wanted to add a directory to the system path I have been adding something like PATH=$PATH:/new/path to the end of /etc/profile.

This is because this is the "answer" that many people provide when you do a Google search on how to do it.

However, in Ubuntu the default path is not set in this file so I have always had the feeling that this is not the "right" way to do this. There must be somewhere else that holds this info?

Well I just discovered it.

The system path is set in /etc/environment.

Here is the default path;

brettg@jupiter:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"


To add a path simply stick a colon at the end followed by your new path;

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/my/new/path"

Easy peasy! (When you know how)

This does not apply to debian (squeeze), the system path is set in /etc/profile same as other systems.

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/addpath.sh

Add this line;

PATH=$PATH:/usr/scripts

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

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/scripts
Enjoy!