Setting the JAVA_HOME environment variable in Ubuntu

て烟熏妆下的殇ゞ 提交于 2019-11-29 04:21:07

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 | cut -f3 -d' ')

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

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

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.

mok

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.

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

djangofan

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!