Ubuntu – Adding JAVA_HOME (JDK) in .bashrc


I just installed Ubuntu and am Java 7u55 (JDK) and am trying to configure JAVA_HOME as an environment variable.

In ~/.bashrc I added:

# Exports

Yet when I close the terminal and open a new shell and type which java or java -version Ubuntu doesn't seem to know what I'm talking about (says program java can be found in one of several packages and prompts me to use sudo apt-get to install one of them).

What am I doing wrong?

Best Answer

First, you have a typo in export line. It should be

export PATH=$PATH:$JAVA_HOME/bin

No space, add a $ character before JAVA_HOME, add /bin

However fixing above line may not fix your problem in installing java. The easiest way to install java is by using webup8 ppa:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

After the last command, the script will automatically download the jdk from Oracle website and install it for you. You can read the tutorial here.