Depending on your distribution it may be easiest to install from your package manager. On Ubuntu, for example, you can do:

Copysudo aptitude install open-jdk

Otherwise, usually the sun (oracle) version of java comes with a .bin file which you need to make executable and run as root in order to get java properly installed.

You shouldn't need to set any environment variables to get java to work, although some applications will require you to set JAVA_HOME, JDK_HOME and/or JRE_HOME to point to the java install's bin directory. You can see where your java install is by looking at where the symlink from

Copy/etc/alternatives/java

points.

Answer from Richard J on Stack Overflow
🌐
SourceForge
vietpad.sourceforge.net › javaonlinux.html
Configure Java environment on Linux
#!/bin/bash JAVA_HOME=/usr/java/j2se JAVA_FONTS=/usr/share/fonts/truetype ANT_HOME=/usr/share/ant PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH export PATH JAVA_HOME JAVA_FONTS ANT_HOME export CLASSPATH=. The file contains various shell commands which set and export necessary environment variables for Java.
🌐
Oracle
java.com › en › download › help › enable_console_linux.html
How do I enable and view the Java Console for Linux or Solaris?
Platform(s): Oracle Enterprise Linux, Oracle Linux, Red Hat Linux, SUSE Linux, Solaris SPARC, Solaris x86, Ubuntu Linux ... The Java Console provides information about the Java version, user home directory, and any error message that occurs while running an applet or application.
🌐
IBM
ibm.com › docs › en › cognos-analytics › 11.2.x
Java setup for Linux and UNIX operating systems - IBM Documentation
January 13, 2026 - Set the JAVA_HOME environment variable to point to the location where the JDK is installed.
Top answer
1 of 1
12

You know how to set the variable in a shell, but for the record you can write:

export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on'

and all programs you start from this shell session after that will have the variable set.

If you want it to be set for every shell you start afterwards, add that line to ~/.profile as well. In that case it will apply to all future shells you start, but not any that are currently running.

.profile will generally work for the GUI as well, but that can be broken by system configuration and how you start things up. This is per-user configuration only.


If you want it set for every user all the time, you can add an assignment to /etc/environment. The format is a little different there: just KEY=VAL on separate lines, with no required quoting and none of anything else.

_JAVA_OPTIONS=-Dawt.useSystemAAFontSettings=on

This is parsed by the pam_env module. There is a per-user ~/.pam_environment file as well, which has the same effect for just the one user. These both require logging out and back in for the change to take effect. The variables will be set for every future login session, both at the console and in X.

Similarly, you can make a file in /etc/profile.d with an export statement in it and it will be loaded into every future session by any user. There will likely be some pre-existing files there to model it on, but just the export line above will be fine.


Alternatively, you can add the export statement in ~/.xinitrc (if you use startx), ~/.xsession, or ~/.xprofile. KDE also supports a directory ~/.kde/env that can contain as many shell files as you want, which contain export statements as above. I would probably prefer one of the other approaches.

🌐
Manula
manula.com › manuals › ipconfigure › orchid-fusion-vms-installation-guide › 21.6 › en › topic › how-to-edit-the-java-options-file-in-linux
How to Edit the Java Options File in Linux - Orchid Fusion VMS Installation Guide - 21.6
The default location for the Java Options file in Linux is: ... This file contains the variable JAVA_OPTS. By default, this variable is empty, but experienced administrators may use this variable to set Java/JVM related parameters.
🌐
DEV Community
dev.to › thekalderon › jdk-setup-on-linux-windows-mac-5d5e
JDK Setup On Linux, Windows, Mac - DEV Community
April 17, 2025 - export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac)))) export PATH=$JAVA_HOME/bin:$PATH
Find elsewhere
🌐
ArchWiki
wiki.archlinux.org › title › Java
Java - ArchWiki
May 15, 2026 - If a program explicitly requires JAVA_HOME, set JAVA_HOME=/usr/lib/jvm/default. OpenJDK is an open-source implementation of the Java Platform, Standard Edition (Java SE), designated as the official reference implementation. There are several distributors of OpenJDK builds such as Adoptium (formerly known as AdoptOpenJDK) and Amazon Corretto. The Arch Linux ...
🌐
HackerNoon
hackernoon.com › setting-up-java-on-ubuntu-linux-and-windows-f60c910d39e3
Setting up Java on Ubuntu linux and Windows
December 25, 2017 - Discover Anything · Hackernoon · Signup · Write · Light-Mode · Classic · Newspaper · Minty · Dark-Mode · Neon Noir
🌐
Redbranch
blog.redbranch.net › 2015 › 06 › 02 › configure-java-security-settings-on-linux
Configure Java Security Settings on Linux » Red Branch
June 2, 2015 - However, you should be able to track down the location of your version of Java by typing the following into a terminal: ... After running the Control Panel choose the ‘Security’ tab and set the ‘Security Level’ to ‘Medium’ (don’t forget to set it back to high when you are finished.)
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › how to set java_home / path variables under linux bash profile
How to Set JAVA_HOME / PATH variables Under Linux Bash Profile - nixCraft
May 25, 2012 - You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users: # vi /etc/profile Next setup PATH / JAVA_PATH variables as follows: export PATH=$PATH:/usr/java/jdk1.5.0_07/bin export PATH=$PATH:/usr/java/jdk1.5.0_07/bin Save and close the file. Once again you need to type the following command to activate the path settings immediately: # source /etc/profile OR # . /etc/profile · 🥺 Was this helpful? Please add a comment to show your appreciation or feedback. Vivek Gite is an expert IT Consultant with over 25 years of experience, specializing in Linux and open source solutions.
🌐
IBM
ibm.com › docs › sl › SS3JSW_5.2.0 › com.ibm.help.gdha_installing.doc › com.ibm.help.gdha_installing.doc › gdha_setting_java_variable_linux.html
Setting Java variables in Linux
February 1, 2022 - Build, govern, and manage your data for generative AI solutions · Use pre-integrated automation technologies to design, build, and run automation applications and services on the cloud
Top answer
1 of 2
20

Feel free to use this as a reference to tinkering with Java at runtime.

Choosing your JRE

To choose your JRE, use

sudo update-alternatives --config java

This will give something like the following output.

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-openjdk/jre/bin/java         1061      auto mode
* 1            /usr/lib/jvm/java-6-openjdk/jre/bin/java         1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java             63        manual mode
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

You can then select which Java runtime you want through the number selection.


Choosing your JVM

Sun/Oracle have two JVM choices, -server and -client. If you select the OpenJDK as your Java runtime environment you have additional options.

When you type java into the terminal with no other parameters, the help lists several optional VMs. I'm not sure which ones come with OpenJDK but 3 popular ones are JamVM, Zero and Cacao

To use these, simply type

java -jamvm 'your other parameters here'
java -cacao 'your other parameters here'
java -zero 'your other parameters here'
java -server 'your other parameters here

The -server VM is normally the default. You can also specify -client but in 64-bit IcedTea6 it appears to run the same version as -server. There are most likely others but I find the default option to be the most responsive.


Setting your Memory

Finally, how to set the memory of Java (just because)

java -Xmx1024m -Xms128m 'your other parameters here'

This limits the memory allowed for the Java program to a maximum of 1024 MB, and sets its initial memory size to 128 MB. This is a great way of defining minimum system requirements. The Java 6 man page for the java command describes these options and others.

That's all. If anyone has additional Java tweaks for Ubuntu then leave them in the comments and I'll add them.

2 of 2
0

To set the default JVM inside an OpenJDK installation you need to edit the jvm.cfg configuration file located inside the /usr/lib/jvm/java-version-openjdk-arch/jre/lib/arch/jvm.cfg

Ubuntu expose the jvm.cfg file inside the /etc/ directory depending on OpenJDK version. /etc/java-6-openjdk/jvm-arch.cfg or /etc/java-7-openjdk/jvm-arch.cfg

The top most -jvmname KNOWN line inside the jvm.cfg file determine the default JVM.

There is no configuration tool available thus you have to locate and edit these files manually.

🌐
Oracle
docs.oracle.com › javase › 7 › docs › technotes › guides › jweb › jcp › jcp.html
Java Control Panel
For Windows and Solaris, Linux, or Mac OS X you can optionally set Java Runtime Settings for the JRE.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › technotes › guides › install › config.html
20 Installing the JDK and the JRE with a Configuration File
April 21, 2026 - Windows: Either Program Files\Common Files\Oracle\Java\java_settings.cfg or Program Files (x86)\Common Files\Oracle\Java\java_settings.cfg. Solaris and Linux: /etc/Oracle/Java/java.settings.cfg
🌐
DEV Community
dev.to › mtendekuyokwa19 › setting-up-for-java-on-linux-133f
Setting Up for Java on Linux. - DEV Community
February 14, 2024 - Now that we have installed the JDK you may want to know version you are using run the command java --version This should tell you the version of java on your machine.
🌐
Linux From Scratch
linuxfromscratch.org › blfs › view › svn › general › ojdk-conf.html
Configuring the Java environment
cat >> /etc/man_db.conf << "EOF" && # Begin Java addition MANDATORY_MANPATH /opt/jdk/man MANPATH_MAP /opt/jdk/bin /opt/jdk/man MANDB_MAP /opt/jdk/man /var/cache/man/jdk # End Java addition EOF mkdir -p /var/cache/man && mandb -c /opt/jdk/man
Top answer
1 of 8
151

Re your first question:

possibly you may be confusing that the webupd8 script is 0.5b. That is the version of the script - it doesnt refer to the java version.

Further to the setting of the javac version.

I suspect you need to explicitly give the path of the javac compiler

i.e.

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6.31-oracle/bin/javac" 1

followed by:

sudo update-alternatives --config javac

With regards to setting up the java chrome plugin.

The master question:

How do I install Oracle JDK 6?

includes this information - since your folder structure is slightly different your link command should be:

ln -s /usr/lib/jvm/java-6.31-oracle/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
2 of 8
104

See this; run

sudo  update-java-alternatives --list

to list off all the Java installations on a machine by name and directory, and then run

sudo  update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]

to choose which JRE/JDK to use.

If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run

sudo  update-alternatives --config java[Tab]

to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then

sudo  update-alternatives --config [javac|java|javadoc|etc.]

will associate that Java task/command to a particular JDK/JRE.

You may also need to set JAVA_HOME for some applications: from this answer you can use

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

for JREs, or

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")

for JDKs.