How to Setup Environment in Java for Windows, Linux, and macOS

0
148
Setup Environment in Java for Windows, Linux, and macOS

Java is the bread and butter of programming world. It is a class and object-based language which runs on Java Virtual Machine (JVM). You will need JVM, JRE, and JDK on the basis of the operating system you are using. However, Java is very much platform independent. By reading this article you will learn more about Java and how to setup environment in Java for Windows, Linux, and macOS.

Things You Need to Learn Before Setting Up Environment in Java

Java JDK JRE and JVM

You will need to look and learn few things if you want to correctly setup environment in Java for different operating systems. The very first is Java Development Kit or JDK. Working with software development requires different set of tools such as Java compiler, Javadoc, and a debugger. These tools will help you immensely if you are a software developer.

The second is Java Runtime Environment or JRE in short form. Programs made by Java need some special Java libraries to run it and JRE has them all. Normal devs do not have to worry about it during development as most end-users need it. You can also refer JRE as the subset of JDK. 

And the last one is Java Virtual Machine also known as JVM. In very simple terms, it simulates a runtime environment with all the specifications needed by Java bytecode to run. Also, most of the hardware and software platform supports it.

Steps to Setup Environment in Java for Windows, Linux, and macOS

For Windows

  1. Move to download website of Java8 JDK. Make sure the webpage is real and official.
  2. You now need to make a selection between (32-bits) and (64-bits). 
  3. Before the downloading starts, you will see a prompt of its terms and conditions.
  4. Read and check the box before it. 
  5. Now, you will have to click the box “download JDK windows 64.exe”.

java windows download

  1. Wait for the download to finish and you will have to open the “exe” installer file.
  2. Follow all the steps you find in the installer and complete the whole process.
  3. Once done, go to your “Control Panel” and look for “System and Security”.
  4. After that, you will have to click on “Settings” and then tap on “Environmental Variable” box.
  5. You now search for the “PATH” in upper white box. Then, tap on “Edit” box.

setting edit

  1. From the right side, click on “New” button. 
  2. Now, go to Java installed place on your hard drive.
  3. C:\Program Files\Java\jdk\bin is one example.
  4. Lastly, click on “OK” box to save the made changes to the setting. 

5 - new

You now want to check if you have done all the steps correctly then open “Command Prompt” window. Type “javac –version” and wait for the results to popup. This will show if you have Java active and running on your device or not.

For Linux

Several methods are available to install and setup Java on Linux. However, here is the very simple steps which only need terminal. Before we do that, we need to have openJDK on the OS. Here are the needed instructions:

  1. Firstly, access “Accessories” in “Application”.
  2. You can now open “Terminal” from here.
  3. Enter this code line in it.
  4. “sudo apt-get install openjdk-8-jdk
  5. For “Java Home” which is “Environment Variable” enter this code line.
  6. export JAVA_HOME = /usr/lib/jvm/java-8-openjdk”

linux java

  1. This code line will work only when you have use default install location.
  2. If not then you will have to switch the location to where it is available.
  3. Now, for “PATH” “Environmental Variable” type this code line.
  4. “export PATH = $PATH:/usr/lib/jvm/java-8-openjdk/bin”
  5. That was the last step. You are now all setup and ready to go.

For macOS

  1. CMD and SHIFT keys will open “Terminal” in macOS. Or just run it from app folder.
  2. First of all, you will need to run some code line to configure.
  3. “java –version 
  4. javac –version”

java mac ver

  1. This will let you know that JDK will work or if it is available on your system computer.
  2. Setup the environment in your Shell Profile.
  3. ~/.bashrc, ~/.zshrc or ~/.profile are some examples.
  4. After that do these code lines.
  5. export JAVA_HOME=/path/to/your/jdk
  6. export PATH=$PATH:$JAVA_HOME/bin
  7. Make sure to switch /path/to/your/jdk to the location where it is available.
  8. Now, apply these changes by running source ~/.bashrc code line in current terminal.

bash java home

  1. To check whether it will work and you have done your part right, run this code line.
  2. java –version

  1. Lastly, if you see version of Java as a result then everything is setup and good to go.

Conclusion

Java is one of the most popular programming languages in the world and for many reasons. Eventhough, it is universally compatible with almost all platform and operating system you will have to set it up according to your personal work case. Also, there are certain things you will have to learn first in order to setup environment in Java correctly. In this article, we have discuss about the Java and how to setup environment in Java for Windows, Linux, and macOS. 

Must Read: How To Use Windows Software on Mac?