If you have a directory
/etc/profile.d you can add or edit an existing file that sets environment variables whenever you log in. Of course, if you don't have that directory you need to do something different.
The way environment variables are set begins with
/etc/profile (no matter what shell you're using; e.g., BASH, C-Shell, KornShell, whatever-shell). The content of
/etc/profile is the first configuration and environment setting that occurs. Generally, you do not want to edit or add anything in
/etc/profile; it's better to modify or add settings somewhere else; that's the purpose of small scripts found in
/etc/profile.d.
For example, I use KornShell system-wide for all users (the functionality of BASH is KornShell and most BASH shell programs will run just fine in KornShell and vice versa).
The file
/etc/profile.d/ksh (which I add to the system) looks like this:
Code:
cat /etc/profile.d/ksh.sh
#!/bin/sh
#ident "$Id$"
#
# Name: $Source$
# Version: $Revision$
# Modified: $Date$
# Purpose: set local environment variables for Korn Shell
# Author: T. N. Ronayne
# Date: 1 Oct 2009
# $Log$
# Set the HOST environment variable
export HOST="`uname -n`"
# Set ksh93 visual editing mode:
if [ "$SHELL" = "/bin/ksh" ]; then
# VISUAL=emacs # ugh
# VISUAL=gmacs # double ugh
VISUAL=vi # ah, elegance
fi
# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
# Do these anyway in case sombody uses a different shell
if [ "$SHELL" = "/bin/pdksh" ]; then
PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
PS1='${HOST}-${USER}-${PWD}: '
elif [ "$SHELL" = "/bin/zsh" ]; then
PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
PS1='$ '
else
PS1='\u@\h:\w\$ '
fi
PS2='> '
export PS1 PS2
Those settings cause the system prompt (in a terminal window) look like this:
Code:
fubar-trona-/home/trona:
That is, the system name, the login name and the current working directory; every time I (or any other user) changes to another directory the prompt shows that directory name.
And the VISUAL environment variable is set to
vi which then does command line editing with
vi editing commands (move the cursor, change or replace characters and words and so on). Handy.
So, on login, the first settings are
/etc/profile, the second settings are any of the files found in
/etc/profile.d (including the file
ksh.sh).
Finally, your environment is set by the content of
.profile found in your home directory and any ".bashrc" file found in your home directory.
All the above is moot if you don't have
/etc/profile.d though.
Let's say that the application you installed was done from source with
configure-make-make install. The default path in one of those will be to install in
/usr/local, where there should be a tree either already existing or created by the
make install directive; there may be a
bin,
doc,
etc,
include,
lib,
lib64,
man,
sbin and
share directories (some may not be there, say
lib64,
sbin,
share; the application you install will have the directories needed in
/usr/local.
And you application will run just fine from
/usr/local. And, most systems default to adding
/usr/local to your PATH environment so that things will be found.
Let's say that you install
Java (which is not installed by default due to licensing). You download
Java from Oracle, you install it using the instructions and you will have a file of some sort -- either in
/etc/profile.d or somewhere else most likely in
/etc -- that will look list this:
Code:
cat /etc/profile.d/jdk.sh
#!/bin/sh
export JAVA_HOME=/usr/lib64/java
export MANPATH="${MANPATH}:${JAVA_HOME}/man"
export PATH="${PATH}:${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin"
(I have Oracle
Java and I install the
JDK version -- which includes
JRE -- if you only install
JRE the
jdk.sh file will point to its location.)
If your distribution has a software collection (that includes
Java) and you install from that it is most likely that the PATH will be set for you.
One last thing: if you use terminal windows to work in, you will want to set the preferences so that the terminal is a "log-in terminal." That causes the terminal program to read all the settings as if you logged in from a cold start; you get all the environment variables set (
/etc/profile,
/etc/profile.d (if it exists), your [I]home/.profle/I] and your
home/.basrc (or whatever) will be scanned and their content will be set.
I realize that this might be confusing -- what happens if you don't have
/etc/profile.d? There will be something, somewhere in you distribution that will do the same thing or, at worse, you can create a
.profile in your home directory and simply copy the examples above into it but it would be better to find out where your distribution does such things -- it'll be there somewhere and should be explained in your system documentation (somewhere).
Hope this helps some.