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
Β 
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
Β 
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
Β 
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
Β 
hophiducanh profile image
Ho Anh β€’

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

Collapse
Β 
punitkulal profile image
Punit Kulal β€’

Great, helped me learn about alternatives in linux as well

Collapse
Β 
zoob profile image
Ricard Salcedo β€’

Thank you Marcos! I am reviving an old PC with Linux and want to have a few different versions of Java installed. This was exactly what I needed.