DEV Community

Install and manage multiple Java versions on Linux using alternatives

Marcos Maia on August 18, 2019

On this post, I will guide you on installing Java on your development Linux machine. I decided to do this post after getting some questions on how ...
Collapse
 
katarman profile image
katarman

Hello thank for the article. How can I have multiple versions of JDK and Java ?
All the Linux distro have open-jdk in /etc/alternatives. Can I have jdk 11 and jdk 8 tohether?
Also I want to have the JDK 8 in /usr and a PATH variable java_home or java8 in system varibles, but I understand that the only way is to add variable in .bashrc.
Can you make it clear ?
Thank you in advance

Collapse
 
thegroo profile image
Marcos Maia

I have added details on the article with JDK 17 and how to switch between versions using alternatives.

Collapse
 
samprogramiz profile image
Samuel Owino πŸ‡°πŸ‡ͺ πŸŒπŸ“±πŸ‘¨πŸΏβ€πŸ’»πŸ”­πŸŒŒ • Edited

If you installed and configured an additional version in the guides, could have been super helpful because that's the whole point - "working with multiple versions of java", otherwise it's just another "How to install java in Linux - Tutorial"

Still forced to just work with /etc/environment | $PATH update

Collapse
 
thegroo profile image
Marcos Maia

Hi, I followed your suggestion and added newest LTS 17 at the end of the post with instruction on how to switch between them. Hope it helps.

Cheers

Collapse
 
varunraje profile image
Varun Deshpande

How to configure open jdk 8 with this?

Collapse
 
thegroo profile image
Marcos Maia

The process is the same, you just have to adjust the paths in your local computer.

Collapse
 
sachajw profile image
Sacha Wharton

This is amazing! Thank you Marcos for this post!

Collapse
 
imadoor profile image
imadoor

Just what I was looking for. Thanks for sharing!

Collapse
 
thegroo profile image
Marcos Maia

I am glad it helped.

Collapse
 
hectorhugocc profile image
Hector Hugo

I have a problem. Using the 'echo $ PATH' command returns me a value but when reviewing the 'etc/environment' file you see another value. The same goes for the JAVA_HOME variable. Could you tell me what it is? Thanks for the support.

Collapse
 
thegroo profile image
Marcos Maia

Hum.... most likely you have in one of these files under your $HOME folder: .bash_profile, .bashrc, .zshrc or similar a configuration setting the $JAVA_HOME specifically to an existing installation? If you have I would recommend you to remove the entry and source the file or restart / login again to see if it's gone. In most cases you don't really need a $JAVA_HOME hardcoded in your profiles(with some exceptions).

If you type only env in your terminal you should see all existent variables in your machine.

Collapse
 
binarydiver profile image
Jason

It was good working!
Thanks a lot.

Collapse
 
punitkulal profile image
Punit Kulal

Great, helped me learn about alternatives in linux as well

Collapse
 
hophiducanh profile image
Ho Anh

I've just added more details. Check out here: github.com/logbasex/coding-notes/b...