Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have added this line at the end of ~/.bashrc

export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java

But when I execute echo $JAVA_HOME, I don't get anything as output, I expected "/usr/java/jdk1.5.0_07/bin/java".

Any idea?

OS: Ubuntu 11.10

share|improve this question
    
If you type source ~/.bashrc, does it work? –  Renan Mar 23 '12 at 17:00
3  
Getting the obvious question out of the way: have you restarted bash / reloaded the rc file since making the change? –  jw013 Mar 23 '12 at 17:00
    
possible duplicate of How do I set a user environment variable? (permanently, not session) –  Gilles Mar 23 '12 at 23:06
    
As a peripheral comment: export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java is not a good practice. Generally, JAVA_HOME is exported as the parent directory where java artifacts are installed. In your case, it would be: export JAVA_HOME=/usr/java/jdk1.5.0_07. Then, you can add the bin dir of $JAVA_HOME to your PATH, eg. export PATH=$JAVA_HOME/bin:$PATH –  Ketan Dec 15 '13 at 5:25
add comment

2 Answers 2

Both /etc/bashrc and ~/.bashrc are whats referred to as non-login files. Meaning they do not get sourced during a login shell unless called by /etc/profile or another file.

If /etc/profile calls it (as is typical) then if you want to test it in your current shell you have to either source it.

/root: #> source .bashrc (source with the command source)

/root: # . .bashrc (source with a period)

Or you have to instantiate a login shell by using su or sudo.

/root: # su - (the dash starts a login shell which will re-source login files)

/root: # sudo su - (using sudo to perform the switch user command)

and of course you could just re-login.

EDIT:

Typically though Java paths are not set using .bashrc they are set as separate scripts in the /etc/profile.d directory. At least on the enterprise distributions I use.

system1:/etc/profile.d # ll
-rw-r--r-- 1 root root  1438 Aug 30  2005 alljava.csh
-rw-r--r-- 1 root root  1682 Jul 13  2005 alljava.sh

system1:/etc/profile.d # cat alljava.sh
if [ -x /usr/$__libdir/jvm/java/bin/java ] || [ -x /usr/$__libdir/jvm/java/bin/jre ] ; then
export JAVA_BINDIR=/usr/$__libdir/jvm/java/bin
export JAVA_ROOT=/usr/$__libdir/jvm/java
export JAVA_HOME=/usr/$__libdir/jvm/java
#....cut for brevity...
share|improve this answer
add comment

To enable the change which you have performed on ~/.bashrc file, you need to execute the command mentioned in the ~/.bashrc file . For this you have to close the terminal and open it again.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.