There are a couple of ways to set the PATH
environment variable: system-wide and individual user.
System-wide is exactly what it sounds like: any user logging in on the system will receive the setting; individual user, on the other hand, is only set for specific users.
There is a directory, /etc/profile.d
. In there are files that are executed at log in for every user (including the root user). You can create a file in /etc/profile.d
for system-wide use (but you would not do so for a specialized, individual user).
Here's an example: I have an application, the Generic Mapping Tools
, or GMT
, that is used to manipulate geographic data sets and, you know, draw maps. Because GMT
is optional software (and it's big) I install in the /opt
is not on any user PATH
, so I need to add it system-wide (so anybody can use it). I do that in /etc/profile.d
with this file, named gmt.sh
# Set the local system $PATH:
Translated, the above defines GMTHOME
is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data used by GMT
) then uses those tokens to add paths to the manual pages and the bin directories for both GMT
. Whenever any user logs in, those PATH
s are set in their shell environment.
To add a file like this to /etc/profile.d
, you must be root (but use su -
to become root, don't log in as root as normal practice) and create the file with a text editor (vi
log in as you
<enter the root password>
<type the lines>
ZZ <save the file>
chmod 755 gmt.sh
Ctrl-D <exit from su ->
The file must be executable, thus the chmod 755 gmt.sh
That's it, log out, log back in, then
That will show you that you did it right.
You can do the same thing for individual users by adding the above lines (don't include the #!/bin/sh
though) in the user's home directory .profile
I prefer .profile
, which is executed at log in (/etc/profile
and the content of /etc/profile.d
are executed at log in to set user environment variables). .bashrc
, on the other hand, is executed for interactive non-log in shells.
Hope this helps some.