0

I'm trying to set the JAVA_HOME environment variable in my .bashrc but every time I log back in it gets unset again to its original value, below is my .bashrc file

# .bashrc

# User specific aliases and functions

export JAVA_HOME=/usr/java/latest

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

What am I doing wrong? Thanks

4
  • "unset again to its original value" Which is it? May 1, 2012 at 17:11
  • As answered below, you should make sure you source other configuration files before your own statements. It may have been overwritten by the global /etc/bashrc file.
    – user13742
    May 3, 2012 at 13:41
  • @Gilles I vote against closing because the solution to his problem (order of file execution) is not even mentioned in the other thread. The subject is similar but the perspective quite different. May 30, 2013 at 23:28
  • @HaukeLaging This isn't about the order of file execution, it's about using the wrong file (.bashrc instead of .profile). May 30, 2013 at 23:29

1 Answer 1

1

Is JAVA_HOME being set in /etc/bashrc? If so, then you should put your custom value after the block where this file is sourced.

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User environment vars should source *after* global environment vars 
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

export JAVA_HOME=/usr/java/latest

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