Configuring Environment Variables
If you are using a Java version that is older than Java 15 (e.g. Java 14 or earlier) then you'll need to set up some system environment variables. Perform the steps below just after you've installed Java, before you download and install your development environment.
Set Up Environment Variables
The editor you're going to use (we'll install this in the next step) needs to know where the /bin directory of your Java installation is. That /bin directory contains the compiler program and the interpreter program, both of which are needed by your editor to compile and run Java programs. We must set up environment variables on your system that contains the location of the /bin directory. Your editor can then read those variables when it needs to know where the compiler and interpreter are.
- First, you must get the exact location of the /bin directory in your Java installation
directory.
Use your preferred file browsing utility to browse to your computer's C:\drive (e.g. it's
usually listed as something like "Local Disk (C:)" under "This PC").
Next, browse to the directories Program Files > Java > jdk-14.0.x (the
14.0.x
might be a different value, depending on what version of Java you're dealing with). Inside the JDK directory, you should see the /bin directory. Go into the /bin directory but don't touch any of the files in that directory.
- Move your mouse up to the address bar and click in any of the white space after the path listed
there.
- Once you click inside the address bar, the complete path to the /bin directory will
appear and become highlighted. Press Ctrl-C on your keyboard to copy that selected
text to the Windows clipboard.
- Keep the copied text in your clipboard - don't copy anything else until you've pasted that text elsewhere. If you prefer, you can open any text editor, word processor, or sticky note app and paste the text there in case you lose it.
- Now we need to find the PATH environment variable and add the location of the JDK's /bin directory to it.
- Use your Windows search to search for system environment
variables. You should see a matching item
called "Edit the System Environment Variables" and "Control Panel" in smaller
letters below it.
Click the item "Edit the System Environment Variables".
- A dialog box will open called "System Properties", and you should already be on the "Advanced"
tab automatically.
You'll see three "Settings" button, and below those, a button that says "Environment
Variables".
Click the Environment Variables button.
- The Environment Variables window appears. It has an area on top where you can edit/create
environment variables for your current account, and an area on the bottom half that allows you
to edit/create environment variables for the whole system.
We want to add an environment variable for the whole system that tells
applications where Java
is located on the computer. Make sure you're working in the bottom half of this
window.
- In the bottom area of the window, click the "NEW" button.
- You'll be presented with a small dialog that asks for the environment variable name and the
environment variable value.
Enter the variable name as
JAVA_HOME
That's the word "JAVA" in all upper-case, followed by an underscore, followed by the word "HOME" in all uppercase. Do not use lowercase and do not add any spaces. It is important that you type the name exactly as shown. - For the variable value, paste the path to the JDK that you copied earlier,
for example,
C:\Program Files\Java\jdk-XX.x.x
(where XX.x.x is the version of Java you have).
- When you're finished, double-check that your 2 inputs are correct. Then click the OK button.
- Once you're back in the Environment Variables window, you should see your new
JAVA_HOME
environment variable in the list in the bottom half of the screen. If you don't see it there (check the screen shot and compare), go back and double-check that you've read and followed the instructions correctly.
- Next, we need to add our new JAVA_HOME variable to the system's
PATH
variable. The PATH variable contains a list of paths or locations of different files and programs. it might appear as "Path" or "PATH", but to make this easier to read I'll use "PATH". This variable is used by your computer: when you run a program, the computer will search all the locations in the PATH so it knows where to find the files it needs. It's a little bit like an address book or contacts list for programs on your computer: when an application wants to find a program, it looks inside any location that's listed in the PATH variable. Some programs won't work if they don't know where certain files are located. For example, when you want to compile and run Java programs, your editor will need to know where the compiler program and interpreter program are located, so it will check the system's PATH variable. - Locate the PATH variable in the list in the bottom half of the window and select it. Then click
the EDIT button.
- You should now see the "Edit Environment Variable" dialog box. It will most likely
contain a list of different paths and locations, and many will include % symbols in them.
Click the NEW button. A small area will open up after the last list item where you can type.
Enter
%JAVA_HOME%\bin
It's important that you type this exactly as shown here, with no spaces, and with the right case (JAVA_HOME in uppercase and bin in lowercase). When you've finished typing, check that you've typed the value correctly. Then press the ENTER key on your keyboard. If you need to edit the value, just click it or select it and click the EDIT button.
NOTE: if you don't see the same screen as above, you might instead just see a field with a very long string of characters. Put your cursor in the field for the variable value and go to the very end. Add a semi-colon and then the java home bin directory e.g. ;%JAVA_HOME%\bin - When you've finished editing the PATH variable, click the OK button to save your changes.
- That's all you need to do in this window, so now make sure you click the OK
button in the Environment Variables window.
- Your changes won't work on your system until you also close the System Properties
dialog. Return to the System Properties dialog and click the OK button.
That takes care of installing and setting up Java. Next, you need to install and setup your Java editor.