简体   繁体   中英

Set JDK path in linux

Something really weird occurs. When I type in:

which java

the output is like:

/private/me/jdk1.8.0_20/bin/java

and when typing in:

echo $JAVA_HOME

the output is:

/usr/java/jdk1.6.0_24

I want to use 'jdk1.6.0_24' and I change all the things in '/etc/profile' and '~/.bashrc' to point it to 'jdk1.6.0_24', such issue still existed. The java I use is still 1.8. Why?

I am pretty sure you need to update-alternatives:

sudo update-alternatives --config java

and select java 1.6.0

Try updating your path as follows:

export PATH=/usr/java/jdk1.6.0_24/bin:$PATH

don't use export PATH=$PATH:/usr/java/jdk1.6.0_24/bin unless you uninstall first the "default" java (if you use this then the java binary in /usr/bin will be found first, which is not what you want).

There is a caveat on this: the binaries in /usr/java/jdk1.6.0_24/bin will be found before than the ones in the rest of the path, which is harmless because you only have java-related binaries on /usr/java/jdk1.6.0_24/bin

caveat #2: make sure you are not redefining PATH after this line or in another script

Go to your home, and show hidden file, then you will find the file .bashrc. Edit and go to the end of the file, then add

export PATH=$PATH:/usr/java/jdk1.6.0_24/bin

$PATH means the current path, in order to append the new value Then, you will use jdk1.6.

Each time you write java -version, you will find the most recent version (jdk1.8), but your program will use jdk1.6

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