简体   繁体   中英

Setting the JAVA_HOME environment variable in Ubuntu

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?

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
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

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

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 .

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

在 Debian/Ubuntu/Linux Mint 中,我们可以添加到 .bashrc export JAVA_HOME=$(update-java-alternatives -l | head -n 1 | sed 's/\\s//g')

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.

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.

你可以在终端输入java,如果它不起作用意味着你没有安装java。如果它起作用,在终端输入javac。如果javac不起作用,你应该设置java环境变量,如果它起作用,可能有问题与你的程序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM