- How to Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide
- Windows
- macOS
- Linux
- Expert Q&A
- You Might Also Like
- About This Article
- Is this article up to date?
- Quizzes
- You Might Also Like
- Java Installation and Path Setting with screenshots
- Download Java
- Installation:
- Set Java Path in System Environment Variable
- Windows 10/8/7, Vista and XP
- Testing Java
- Summary
- Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux
How to Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions.
This article has been viewed 323,663 times.
Are you seeing Java errors like «JAVA_HOME is not defined correctly?» or «JAVA_HOME is set to an invalid directory?» If you’ve recently installed the Java Development Kit (JDK) or the Java Runtime Environment (JRE), you’ll need to set your JAVA_HOME variables and configure the path so applications know where to find Java. This wikiHow article will show you the easiest ways to change or set the Java home path on Windows, macOS, and Linux.
- Before you can set JAVA_HOME, you’ll need the full path to your JDK or JRE installation.
- Once you set the JAVA_HOME environment variable, you can run the command echo $JAVA_HOME to see the new path.
- To set the Java home and path on Linux or macOS permanently (even after a reboot), add the environment variables to your .bashrc or .zshrc file.
Windows
- Open File Explorer, click This PC in the left panel, then navigate to C:\Program Files\Java. The directory you’re looking for should have the name of the JDK version, such as C:\Program Files\Java\jdk-19.
- If you installed the JRE instead of the JDK, you’ll have something like C:\Program Files\Java\jre1.8.0_351 instead.
- You can also open the command prompt and run the command wmic product where «Name like ‘%%Java%%'» get installlocation,Name . This will tell you the full path of the JDK, even if you haven’t yet set JAVA_HOME.
- Press the Windows key on your keyboard and type advanced system .
- Click View advanced system settings in the search results.
Click the Environment Variables button. You’ll see it at the bottom-right corner of the System Properties window.
- If you have multiple installations of the JDK and want to change JAVA_HOME to your new installation, select the current JAVA_HOME user variable and click Edit… instead.
- If you’re editing the current JAVA_HOME path, you’ll already have JAVA_HOME here. So, you can skip this step.
- If you’re adding a second path to JAVA_HOME, just type a semicolon (;) after the first path, then enter the second path.
- If you’re replacing an old JAVA_HOME path, just delete the current path and enter the new one.
- If you want other users on this PC to be able to access Java binaries from the command line, repeat this step for the «Path» variable under «System variables» as well.
- Click the New button at the top.
- Enter the full path to the JRE or JDK with \bin at the end. For example, C:\Program Files\Java\jdk-19\bin or C:\Program Files\Java\jre1.8.0_351\bin.
- Click OK.
- You won’t need to restart your computer for the changes to take effect, but you will need to relaunch any apps that were trying to access Java.
- Open a new command prompt window and run the command echo %JAVA_HOME% to display the new path to JAVA_HOME.
- Make sure this is a new command prompt window. If you still have the same window open, the command will fail because it doesn’t have the new environment variables.
macOS
Open a Terminal window. To open Terminal, search for Terminal in Spotlight. Or, you can open Finder, click the Go menu, select Utilities, and choose the Terminal app.
- If you have more than one Java installation and want to see the paths to all of them, use /usr/libexec/java_home -V instead.
Copy the path and paste it somewhere handy. Highlight the path to the Java installation you want to use as JAVA_HOME, press Cmd + V to copy it, then paste it into a sticky note or text file.
- Type cd ~ and press Return.
- Type open .zshrc and press Return. This should open the file in a text editor.
- If the file is not found, type echo > .zshrc and press Return. Then, run open .zshrc again.
- export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home
- Replace /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home with the full path to the /Contents/Home directory of your Java installation if it’s different.
Type source .zshrc and press ⏎ Return . Once you’ve edited your profile, this command ensures that your environment variables will be updated for the current terminal window (and any other windows you open from now on).
- If you had any other windows open that were attempting to find Java binaries, close and reopen them.
- Shopping for PC accessories or office supplies? Check out our coupon site for Staples discounts or our coupon site for Office Depot.
Linux
- readlink -f `which javac`
- If that doesn’t work, try running update-alternatives —list java .
- If neither of these commands works, run whereis java , which will usually result in a symbolic link like /usr/bin/java.
- Once you get the directory, find out where it links using ls -la /bin/java .
- If that points you to another directory, e.g., /etc/alternatives/java, run ls -la /etc/alternatives/java .
- At that point, you should see a much longer directory, which is actually the home to the Java binaries. For example, usr/lib/jvm/java-11-openjdk-arm64/bin/java . This is the directory you want.
- echo «export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64» >> ~/.bashrc
- echo «export PATH=$PATH:$JAVA_HOME/bin» >> ~/.bashrc
Expert Q&A
In Linux, you can set JAVA__HOME for all users by editing the global .bashrc, which is located at /etc/bash.bashrc. Just use echo and replace ~/.bashrc with /etc/bash.bashrc .
You Might Also Like
Use Easy Windows CMD Commands to Check Your Java Version
How to Do Division in Java (Integer and Floating Point)
How to Compile and Run Java Programs Using Notepad++
Simple Steps to Type a Bunny with Your Keyboard
About This Article
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 323,663 times.
Is this article up to date?
Quizzes
You Might Also Like
Use Easy Windows CMD Commands to Check Your Java Version
How to Do Division in Java (Integer and Floating Point)
How to Compile and Run Java Programs Using Notepad++
Java Installation and Path Setting with screenshots
This is very fundamental chapter of learning java in which you will learn downloading Java, Installation and setting path. If you know how to signup in facebook you are capable in doing all these tasks yourself. It is as easy as posting your status on facebook or twitter. Believe me, I am not joking. I will guide you at every steps with screenshots and at the end you feel proud on yourself.
Download Java
If your PC doesn’t have Java, download it from java official site. Go to Java Official Site
Installation:
After downloading Java, it’s time to install it on your PC. It is not a difficult task and as easy as installing other windows software.
Steps 2: The installation process is started. Windows security will ask you whether allow or not to run this software. Click yes if asked.
Now, it’s time to check whether Java is installed on your PC or not.
Go to C Drive > Program Files. Here in the list you will find Java folder.
If you get this folder it means Java has been installed on your PC. But it doesn’t mean you are ready for writing and executing java program. One more step is ahead. It is setting Path in System Environment Variable. Until you set path you are not able to compile java code.
Set Java Path in System Environment Variable
In order to setting java path you need to open system variable windows first. To open system variable windows you follow these steps.
Windows 10/8/7, Vista and XP
Steps 1: Right click on MyComputer, Computer or This PC and select properties.
Steps 2: In the left side, there is link Advanced System Settings. Click on it.
Steps 3: Go to Advanced tab and click on Environment Variables.
Steps 5: In the Variable Name write JAVA_HOME and in the Variable Value field Write Java Installation path. It is in your program file location as C:\Program Files\Java\jdk1.8.0_65
Steps 9: Add %JAVA_HOME%\bin at the end. You must put a semicolon (;) at the end of previous value before adding new value. Do not delete or alter previous written value. Softly put a semicolon at the end if there is no semicolon and then put your JAVA_HOME value.
Testing Java
Now it’s time to test whether Java is working on your machine or not. In order to test java, do the following steps.
1. Open command prompt. To open command prompt press windows + R key and write cmd and press enter. Write javac in the command prompt. If you get list of java option then cheers! Java is ready on your machine and now you can start java journey.
Summary
In this chapter you have learned how to Download, Install and set path for Java. Setting environment variable is little bit tricky but if you are learning Java then this level of tech is expected from you. In the next chapter you will write and execute your first JAVA program.
Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux
As always, the writeup is super practical and based on a simple application that can work with documents with a mix of encrypted and unencrypted fields.
We rely on other people’s code in our own work. Every day.
It might be the language you’re writing in, the framework you’re building on, or some esoteric piece of software that does one thing so well you never found the need to implement it yourself.
The problem is, of course, when things fall apart in production — debugging the implementation of a 3rd party library you have no intimate knowledge of is, to say the least, tricky.
Lightrun is a new kind of debugger.
It’s one geared specifically towards real-life production environments. Using Lightrun, you can drill down into running applications, including 3rd party dependencies, with real-time logs, snapshots, and metrics.
Learn more in this quick, 5-minute Lightrun tutorial:
Slow MySQL query performance is all too common. Of course it is. A good way to go is, naturally, a dedicated profiler that actually understands the ins and outs of MySQL.
The Jet Profiler was built for MySQL only, so it can do things like real-time query performance, focus on most used tables or most frequent queries, quickly identify performance issues and basically help you optimize your queries.
Critically, it has very minimal impact on your server’s performance, with most of the profiling work done separately — so it needs no server changes, agents or separate services.
Basically, you install the desktop application, connect to your MySQL server, hit the record button, and you’ll have results within minutes:
DbSchema is a super-flexible database designer, which can take you from designing the DB with your team all the way to safely deploying the schema.
The way it does all of that is by using a design model, a database-independent image of the schema, which can be shared in a team using GIT and compared or deployed on to any database.
And, of course, it can be heavily visual, allowing you to interact with the database using diagrams, visually compose queries, explore the data, generate random data, import data or build HTML5 database reports.