tags:

views:

34

answers:

3

Assume I am compiling the JDK from source downloaded from Oracle.

Now the JDK is extracted into /opt/oracle/jdk/

I am exporting the JAVA_HOME and the path environment variable in /etc/profile.

Is it the recommended way?

+1  A: 

Thats fine to set JAVA_HOME, but there are a few other things you should also do.

You should also set it up as an alternative for java and javac and register it using the alternatives system.

Why are you compiling the JDK from source? Ubuntu does host Sun Java packages.

Freiheit
Ubuntu's one is outdated, not so good for performance.Btw, I heard about /etc/environment, anyone using it?
Howard
A: 

i always just set it in my .bashrc or .bash_profile...

hvgotcodes
this won't work as soon as you're trying to run some Java app from an init script during boot or as cron job (just to give two common examples).
sfussenegger
right, you would have to set the proper variables in the init or cron entry....
hvgotcodes
or in /etc/profile like the OP did. http://www.faqs.org/docs/securing/chap6sec64.html
Freiheit
A: 

I am exporting the JAVA_HOME and the path environment variable in /etc/profile.

That's one way to do it. But consider that different users (or different applications) on the machine may need to use different Java installations. So other options are for users to set the environment variables in their personal shell profiles, and for applications to set them in wrapper scripts, "init.d" scripts or whatever.

There is no single "right" way to do this. Pick a way that best fits your needs.

Stephen C