user353829
user353829

Reputation: 1434

Setting PATH for 'ROOT' in Red Hat 5

I have edited '/etc/profile' and added the following:

export JAVA_HOME=/usr/java/jdk1.6.0_21

However, when logged in as 'root': '# echo $JAVA_HOME' lists a different path.

How do I configure 'root' to pick the above path?

NB: Exporting paths in 'bashrc' or '.bash_profile', for root, did not work for account 'root'.

Upvotes: 3

Views: 15218

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753455

There are only a limited number of places where the value can be mis-set for root. The home directory for the superuser is /root, so you should first look in /root/.bashrc and /root/.bash_profile. You might need to look in /etc/bashrc, too.

If none of that yields enlightenment, you could try debugging where the environment is set by adding set -x (and perhaps env) to the top of /etc/profile, maybe only if the person running it is root (so as not to disturb other users), and track what is executed and set. Use the env command to diagnose whether JAVA_HOME is already set on entry to /etc/profile.

The Bash manual (4.0 edition) says:

§6.2 Bash Startup Files

[...]

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the ‘--login’ option, it first reads and executes commands from the file ‘/etc/profile’, if that file exists. After reading that file, it looks for ‘~/.bash_profile’, ‘~/.bash_login’, and ‘~/.profile’, in that order, and reads and executes commands from the first one that exists and is readable.

Unless you have done something unusual, root's ~ is /root.

Upvotes: 3

Related Questions