LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   JAVA_HOME in /etc/profile doesn't work in GNOME terminal (https://www.linuxquestions.org/questions/linux-newbie-8/java_home-in-etc-profile-doesnt-work-in-gnome-terminal-421628/)

JoseVilla 03-04-2006 02:02 PM

JAVA_HOME in /etc/profile doesn't work in GNOME terminal
 
Hello world.
I wanted the JAVA_HOME environment variable and the JAVA_HOME/bin set for all users in my system (Debian 3.1), so I changed the "/etc/profile" file.
Here's a stract.
Code:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi
ANT_HOME="/usr/local/apache-ant-1.6.5"
export ANT_HOME
JAVA_HOME="/usr/java/jdk1.5.0_06"
export JAVA_HOME
PATH=$ANT_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH

umask 022

I go to tty1 and echoing $JAVA_HOME works.
But, with GNOME terminal it doesn't work.
I even restarted my computer.
The strange thing is that I did the same for my Fedora Core 4 and everything goes well.
Please some help, I really need to get rid of this.

anti.corp 03-05-2006 08:07 AM

Hi,

Try to alter the second path line so it points to your install dir. Somthing like this:
Code:

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/jdk1.5.0_04/bin"

There is also alot of good tutorials concerning this subject. Try to check this one out:
http://wiki.serios.net/wiki/Debian_J...K_installation

JoseVilla 03-06-2006 05:59 PM

Thank you for replying and sorry for not having done the same (no Internet on sunday).I'll give it a try tonight and share my results.

JoseVilla 03-09-2006 03:30 PM

I tried doing the adding in the second line and it didn't work.
The changes I made were effective in the tty1 but not in the GNOME terminal.

g_srinivas 03-09-2006 03:41 PM

Hi, I am not an expert but i recently installed java sdk and for me i installed java in the specified default locations "/opt/jdk1.5.0_06/" and after modification of my /etc/profile, it looks following way:

Code:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/opt/jdk1.5.0_06/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/opt/jdk1.5.0_06/bin"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 022

export CLASSPATH=$CLASSPATH:/var/java_dev

Above i set the path purposefully in both path because i wanted to run java for all users. With above settings my java works fine both in tty1 and also in GNOME terminal. Maybe you could try something similar and it might work for you as well.

JoseVilla 03-23-2006 11:05 PM

Guess what...I tried your suggestion and the problem is the same. Thanks for your time guys.
I don't know what happens exactly but running
Quote:

source /etc/profile
puts everything in order (JAVA_HOME,ANT_HOME...variables I defined in that file). It seems the profile file is not read.
I have installed Ubuntu on my computer and have the same problem.
I finally managed some way to have my JAVA_HOME and other variables consistently but not much conviniently.

I hope someone could explain why this all happens. I've read a lot about the subject and my case seems to be strange.

Thanks for helping.

rickh 03-23-2006 11:19 PM

This is what my /etc/profile looks like using Debian Testing:
Code:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

JAVA_HOME="/usr/lib/java"
export JAVA_HOME

umask 022

The only change I made from it's default set-up was to insert the two lines near the end about JAVA_HOME.

JoseVilla 04-09-2006 12:52 AM

I finally got it.
The solution was understanding what a login shell is.
When in ttyx you use a login shell while when a gnome terminal (pts) you use a non login shell. So I had to do the exporting of variables in the /etc/bash.bashrc (for no login shells) and /etc/profile (for login shells) files.
Now it works!!!

For a more detail explanation look at:
http://telin.ugent.be/~slippens/drup...hrc_and_others

Thanks for your time and help


All times are GMT -5. The time now is 09:49 PM.