This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Where is Java Set up? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Where is Java Set up?" Watch "Where is Java Set up?" New topic

Where is Java Set up?

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1064
I installed Java 5 on my Linux server (executed the RPM file), but when I log in via putty and type: "java -version", I still see that it's 1.4.2..

Under Red Hat 9, what file do I need to modify so that the machine recoginizes and uses the new Java 5 installation? Maybe there are other steps?

My java 5 install is in /usr/local/java/java5, but the version the machine is using is in /usr/java/jdk -- which is the 1.4.2 version.

Also, if I get strange side effects from Java 5 in my sites, I'll need to go back to Java 1.4.2 so I'm hoping that the version of Java the machine uses is just a config value in a file somewhere.

One last question -- do I need to reboot the machine after making the change?

Look forward to any and all replies!!!

Thanks in advance.

-- M
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

There is only one time when you need to reboot a Linux machine, and that's when you upgrade the kernel itself.

When you (or anybody/anything) executes a program from a shell without specifying an absolute path to the program file, the shell uses the PATH environment variable to find the program. It doesn't matter how PATH is set -- all that matters is the value in the shell where the program is run.

There's a global file /etc/profile which contains settings that can apply to all users; PATH is sometimes set there. Then individual users have their own shell startup files in their home directory: they may have .bashrc, .bash_login, .bash_profile, and/or .profile. Depending on how things are set up, setting PATH in any one of these would work.

Likewise, many Java codes like to have the JAVA_HOME environment variable set; it's used by scripts that start Java programs, though, not by the shell or any other Linux things.

Anyway, look at /etc/profile. If there's a PATH variable that mentions Java, edit it as root to change it, then open a new shell window and try "java -version" again. If there's a JAVA_HOME in /etc/profile, you can fix that too.

Otherwise, look in your own home directory for the hidden file .bashrc, and possibly make those changes there.

[Jess in Action][AskingGoodQuestions]
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1064
Wow, great reply!!!

I didn't see that the path in /etc/profile mention the java directory at all.

On my VPS, I have a /home directory where I keep all my hosted domains. In the root directory, using CuteFTP Pro (which I think sees hidden files), I didn't see any bash files. I also looked in each of the home directories.

Maybe I need to use putty?

-- M
Avinash Rawana
Ranch Hand

Joined: Feb 22, 2006
Posts: 31
I'm not sure how much you've modified but maybe you want to figure out where the JDK is actually located. I usually keep mine in /opt/java, then symlink to /opt/jdk1.whatever. Try doing ls -l `which java` because maybe that will reveal the symlink and you can find the 1.4.2 folder. When in doubt, I would really consider removing the java RPM you've got, then placing your JDK in /opt/ (or any other place that is convenient) then modifying the /etc/profile as previously suggested. I would never leave a package management system (such as Redhat's RPM) in control of Java's SDK because it always adds variables that may or may not be to your liking. Also, if you want to see hidden files, use putty and 'ls -a'


--------------<br />Avinash A. Ramana<br />NYIT Student<br /><a href="" target="_blank" rel="nofollow"></a><br />
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022

The Sun JDK RPM does not set any magic Windows registry-style information or do funny things to your filesystem. It does one and only one thing, which is explode an archive into a directory named /usr/java/xxxxxx, where, for example, JDK is named /usr/java/j2sdk1.4.2_12 and JDK 1.5.0 would be /usr/java/jdk1.5.0.

Although recent Fedora systems have included the Debian "alternatives" system for making Java available to apps, I don't think that was in RH9. Fortunately, since I hate it. Instead, you can assign a JDK or JRE to each app on a per-app basis. Normally this is done by pointing the JAVA_HOME environment variable to the jdk or JRE you want. Since Red Hat is geared towards unattended startups, most init-script services (such as the Tomcat RPM) will have a place to get that setting so you don't have to edit the init scripts. For example, /etc/tomcat4/tomcat.conf or something like that.

For development, I normally set a default in my ~/.bash_profile script, where I also set other useful things like ANT_HOME. And, of course, add $JAVA_HOME/bin and $ANT_HOME/bin to my PATH.

In short, you can be running as many different versions of Java as you like. It's all in how you set them up.

Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link:
subject: Where is Java Set up?