6

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
JAVA_HOME=/home/myuser/sandbox/java/7u55/jdk1.7.0_55
export PATH=$PATH:JAVA_HOME

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?

4 Answers 4

10

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.

4

You have set the environment variable JAVA_HOME, but this is only a value used by applications that want to know where the JRE or JDK are.

The PATH is what your shell is looking in when you try to run executables. So when you type java -version, it is looking in the JDK folder. Note that java is actually inside $JAVA_HOME/bin. That's why it can't find it.

That's the explanation.

The fix is to either add it to the $PATH properly:

export PATH=$PATH:JAVA_HOME/bin

or to run update-alternatives and add the JDK path to the system's java alternatives.

For example

update-alternatives --install "/usr/bin/java" "java" "/home/myuser/sandbox/java/7u55/jdk1.7.0_55/bin/java" 3
1

Sqoop not finding jdk thats why this error coming. By default jre used and it don't have javac file which is required to compile sqoop jobs.

Solution:

if jdk installed on the system then configure the same in hadoop-env.sh file like:

# The java implementation to use.  Required.
export JAVA_HOME=/opt/jdk1.8.0_151/

And in .bash_profile file.

like:

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/jdk1.8.0_151/bin

then run source . .bash_profile

thats it now test sqoop job will works fine.

0
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
1
  • 1
    It's a good practice to briefly explain what's happening, Shedrack. Sep 13, 2021 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .