11

I'm pretty new on ubuntu, at some point in the terminal I'm running:

mortar local:illustrate pigscripts/retail-recsys.pig purchase_input -f params/retail.params

but I have this following error:

A suitable java installation could not be found. If you already have java installed
please set your JAVA_HOME environment variable before continuing. Otherwise, a suitable java installation will need to be added to your local system.

Installing Java

On OSX run javac from the command line. This will intiate the installation. For Linux systems please consult the documentation on your relevant package manager.

But I'm pretty sure I have Java, so please how can I set my JAVA_HOME environment variable?

Makoto
  • 104,088
  • 27
  • 192
  • 230
user2461031
  • 513
  • 2
  • 7
  • 17
  • 1
    I did some mousing around, and [I found this document page](http://help.mortardata.com/data_apps/recommendation_engine/install_mortar) related to Mortar. I'm willing to bet that's what you want to use to export your JAVA_HOME when you're running/installing it. – Makoto Apr 17 '14 at 04:48

9 Answers9

20

First, you need to decide which installed version of Java to use? No fear, you can pick any you have -

update-java-alternatives -l

One "easy" solution is to add this to "$HOME/.bashrc",

export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | awk -F ' ' '{print $NF}')

This picks the first installed JDK and takes it's JAVA_HOME (the third field) - on my system that's

/usr/lib/jvm/java-1.7.0-openjdk-amd64
lrkwz
  • 6,105
  • 3
  • 36
  • 59
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • this is only a temporary solution, and will get cleared upon reboot. – IgorGanapolsky Mar 29 '15 at 15:47
  • 2
    @IgorGanapolsky No, if you add it to ".bashrc" it will not. – Elliott Frisch Mar 29 '15 at 18:29
  • On Ubuntu 14.04, a symlink /usr/lib/jvm/default-java was created when I installed jdk via apt. I used this for the JAVA_HOME environment variable. – RobotNerd Dec 01 '16 at 22:47
  • 1
    I needed to update this solution for Ubuntu 16.4 to take out the multiple spaces between the 3 parts. So I use `export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | sed 's/ */ /g' | cut -f3 -d' ')` – Niels Basjes Sep 28 '17 at 15:30
6
export JAVA_HOME=/usr/lib/jvm/java-7-oracle

in your ~/.bashrc file.

If you want this environment variable available to all users and on system start then you can add the following to /etc/profile.d/java.sh (create it if necessary):

export JDK_HOME=/usr/lib/jvm/java-7-oracle
export JAVA_HOME=/usr/lib/jvm/java-7-oracle

Then in a terminal run:

sudo chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh
Sanjay Rabari
  • 2,091
  • 1
  • 17
  • 32
2

The simplest method to set environment variable is with export:

    $ export JAVA_HOME="/usr/bin"

This will temporarily set the desired variable. You can check if it was set with:

    $ echo $JAVA_HOME

or

    $ printenv

If you want a more permanent solution, append 'export JAVA_HOME="/usr/bin"' to .bashrc or .bash_profile file.

To check if java is properly installed:

    $ which java
    $ which javac

You should get similar output:

    /usr/bin/java
PovilasB
  • 1,488
  • 1
  • 15
  • 25
2

For JAVA_HOME to point to the active jdk, add to your ~/.bashrc

export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')

which will dynamically set the $JAVA_HOME to the JDK selected by update-alternatives.

All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
1

put the line export JAVA_HOME=/usr/lib/jvm/java-xxx-oracle in your .profile file at home directory. Note that you have to replace xxx. You may need to logout and login again

chanaka777
  • 380
  • 1
  • 2
  • 10
1

In Debian/Ubuntu/Linux Mint, we could add to .bashrc export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | sed 's/\s//g')

user271777
  • 21
  • 1
0

Normally you can set paths in

~/.bashrc

with export JAVA_HOME=/usr/lib/jvm/java-version

However you may followe instructions from here for a comprehensive instruction.

Community
  • 1
  • 1
Mohsen Kamrani
  • 7,177
  • 5
  • 42
  • 66
-1

By far, the ultimate guide to doing this is here. You don't need to set PATH as much as you just need to adjust the default 'java alternative' location.

Community
  • 1
  • 1
djangofan
  • 28,471
  • 61
  • 196
  • 289
-1

you can type java in terminal,if it does not work means your did not install java.if it works, type javac in terminal.if javac dose not work,you should set the java environment variable,if it works ,there maybe something wrong with you program.

nico zhang
  • 51
  • 6