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

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
marchinram
  • 103
  • 2
  • "unset again to its original value" Which is it? – Ignacio Vazquez-Abrams May 01 '12 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. –  May 03 '12 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. – Hauke Laging May 30 '13 at 23:28
  • @HaukeLaging This isn't about the order of file execution, it's about using the wrong file (`.bashrc` instead of `.profile`). – Gilles 'SO- stop being evil' May 30 '13 at 23:29

1 Answers1

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
George M
  • 13,589
  • 4
  • 43
  • 53