Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple versions of Java in Ubuntu

I have a Ubuntu machine where I already have one JDK version which is installed. Next I have downloaded the second version into /usr/local.

Now, I want to run a program against the second JDK which is in /usr/local, i.e., I will copy a sample .java program in /usr/local/bin and then execute it.

But the problem is, even If I navigate to the /usr/local/bin and type $ java -version, I am getting the one which is installed in the first place. Is there any solution for this?

like image 592
user1907849 Avatar asked Feb 12 '23 16:02

user1907849


2 Answers

type sudo update-alternatives --config java

The select the version you want.

And I think this question should be moved to askubuntu.

like image 94
maress Avatar answered Feb 15 '23 04:02

maress


When you run java with no path, then your shell looks in your $PATH environment variable to find java. If you want a specific java, you need to either change your $PATH, or run it with a path, like:

/usr/local/bin/java

or if you really want to cd there first, you could run

./java

from /usr/local/bin

like image 30
e.dan Avatar answered Feb 15 '23 06:02

e.dan