chrisTina
chrisTina

Reputation: 2368

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?

Upvotes: 0

Views: 7856

Answers (3)

morgano
morgano

Reputation: 17422

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

Upvotes: 1

Jama Djafarov
Jama Djafarov

Reputation: 358

I am pretty sure you need to update-alternatives:

sudo update-alternatives --config java

and select java 1.6.0

Upvotes: 2

Riadh
Riadh

Reputation: 1206

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

Upvotes: 0

Related Questions