Setting the JAVA_HOME environment variable in Ubuntu

I am new to ubuntu, at some point in the terminal that I run:

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

but I have the following error:

Unable to find a suitable java installation. If you already have the Java version installed before continuing, set the JAVA_HOME environment variable. Otherwise, a suitable java installation will need to be added to your local system.

Java installation

On OSX, run javac from the command line. This will result in installation. For a Linux system, please refer to the documentation of your respective package manager.

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

+8
java ubuntu java-home
source share
9 answers

First, you need to decide which installed version of Java to use? No fear, you can choose any that 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 | cut -f3 -d' ') 

This selects the first installed JDK and accepts it JAVA_HOME (third field) - on my system

 /usr/lib/jvm/java-1.7.0-openjdk-amd64 
+15
source share
 export JAVA_HOME=/usr/lib/jvm/java-7-oracle 

in your ~/.bashrc .

If you want this environment variable to be accessible to all users at system startup, you can add the following to /etc/profile.d/java.sh (create if necessary):

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

Then in terminal run:

 sudo chmod +x /etc/profile.d/java.sh source /etc/profile.d/java.sh 
+4
source share

The easiest way to set the environment variable is to export:

  $ export JAVA_HOME="/usr/bin" 

This will temporarily set the desired variable. You can check if this has been installed with:

  $ echo $JAVA_HOME 

or

  $ printenv 

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

To check if Java is installed correctly:

  $ which java $ which javac 

You should get a similar output:

  /usr/bin/java 
+3
source share

put the line export JAVA_HOME=/usr/lib/jvm/java-xxx-oracle in the .profile file in your home directory. Please note that you must replace xxx. You may need to log out and log back in.

+1
source share

You can usually set paths to

~ / .bashrc

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

However, you can follow the instructions here for comprehensive instructions.

0
source share

For JAVA_HOME , to point to 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 $JAVA_HOME to the JDK selected by update-alternatives .

0
source share

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

0
source share

Far the ultimate guide to this subject here . You do not need to set PATH as much as you need to configure the default java alternative location.

-one
source share

you can type java in the terminal, if it doesn’t work, that means you have not installed java.if, it works, enter javac in the terminal. If the javac dose does not work, you should set the java environment variable, if it works, there may be something wrong with your program.

-one
source share

All Articles