I followed this thread to solve my problem, I have the same problem with a different version of JDK and for some reason it didn't work. I still get -bash: JAVA_HOME: command not found when I type JAVA_HOME to my terminal.
I have JDK1.8.0.45 located at Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home which I can access with /usr/libexec/java_home
Using
echo "export JAVA_HOME=/usr/libexec/java_home" >> ~/.profile
~/.profile
I do get
"export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home"
saved to ~/.profile, and I can check this using /usr/bin/open ~/.profile
But I do not understand why JAVA_HOME still doesn't work and I need this to install maven.
Thanks!
My ~/.bash_profile has this line in it, and it's been working fine.
export JAVA_HOME=$(/usr/libexec/java_home)
This line basically says "run the program named /usr/libexec/java_home and export its output as a variable named JAVA_HOME."
I suggest opening your .profile or .bash_profile in a text editor rather than using echo statements to append new lines to it. That way you can see everything that's in the file and make sure other old lines in the file aren't causing you issues.
After you make a change to .bash_profile, make sure you open a new terminal window before testing it.
You can check the value of any environment variable (including JAVA_HOME) by simply echo'ing its value:
echo $JAVA_HOME
In my case the output of that echo command is:
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
Probably you misunderstood things. JAVA_HOME is not a command, it's an environment variable. You can't call JAVA_HOME in your terminal since - in fact - there is no such command, what your error message says.
You can see this variable's value by:
echo $JAVA_HOME
If it is set and points to a proper location then it's fine. Some tools that expect this variable to be set (e.g. Maven or Java IDEs) will work well.
Related
I have tried all approaches I can find online, but none of them works.
I want to set JAVA_HOME and PATH environment variables permanently, so that in IntelliJ I can issue commands like "mvn".
I have written my script into .bash_profile as shown below:
screenshot
But after I restarted my Mac and issued echo $JAVA_HOME, the output is still empty.
I also tried launchd.conf as said in this answer, but it didn't work either.
Could someone help me here?
Thanks in advance!
For osx add this in your ~/.profile or if you are using zsh inside ~/.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home
restart your terminal or simply apply your changes
source ~/.profile
refer this to know more about related to this question
& also refer this to know more about installation process of Amazon Corretto 8.
If you are using zsh you can import .profile config inside ~/.zprofile
emulate sh
. ~/.profile
emulate zsh
Check your enviroment variables with
env
then check if your config files are in the right directory. Read /etc/profile e.g.
nano /etc/profile
There can you find the path to bashrc file
I'm trying to get a working build system for Java on Sublime Text 3, but whenever I try to run anything, i just get bash: javac: command not found.
The strangest thing about this is that I can run the javac command from a terminal, as I have added the line
export JAVA_HOME=/usr/lib/jvm/java-14-openjdk && export PATH=$JAVA_HOME/bin:$PATH
to the .bashrc file in my home directory.
So I have no idea why I can run Java files using javac and java from the terminal, however Sublime Text cannot.
Here is what I have for my build system:
{
"shell_cmd": "javac \"$file_name\" && java \"$file_base_name\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.java",
}
I am using Manjaro 20.
I see that you are using Manjaro, which is Arch derivative; instead of setting the JAVA_HOME variable, you should use archlinux-java to set the default JDK version.
archlinux-java is part of java-runtime-common package.
When something is wrong, Sublime will print your current path variable (example). Make sure the paths are set correctly.
I tried your build system on my Arch machine, and it is working correctly, I also tried setting the JAVA_HOME variable, and it is still working.
Using Sublime Text 3 Build 3211
For future users with the same issue, I solved it by specifying the path variable in my build system by adding:
"path":"your/directory/here"
The whole thing where I added the line to .bashrc turned out to be completely unnecessary, as this fixed it.
JAVA_HOME is not set currently. Please set JAVA_HOME. I want to run appium programs but its throwing this weird error
Even java_home path not displaying in terminal. Currently displaying blank
My bash profile
JAVA VERSION Is also getting displayed
try the following command:
vim .bash_profile (do you see export JAVA_HOME=$(/usr/libexec/java_home) under the file) ?
If not then you need to add it there.
If already added then run source .bash_profile, it reloads the file. And the path is set.
The first bash line is incorrect.
export JAVA_HOME=$(/usr/libexec/java_home)
Should be:
export JAVA_HOME=/usr/libexec/java_home
I did the following steps but java does not seem to be working for me, do I need to restart my system if yes then why?
1. Right click My Computer->Advence Option->Environment Varibles->System Variables
2. variable : Path->Edit
3. Copy your jdk bin directory i.e.C:\Program Files\Java\jdk1.7.0_51\bin
4. Paste it after putting a semi-colon(;) in value section
i am getting below error while running java in cmd
C:\Users\User>java -version
Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
No, but you will need to close and recreate any cmd windows, running java programs, or the like.
To check it's correct, open a new cmd window and type set -> review the information for PATH and JAVA_HOME.
You should set two things:
JAVA_HOME
PATH
The first lies under the "User variables for [your user name]" section. Add the JAVA_HOME variable and set it to where your jdk is installed. i.e. C:\Program Files\Java\jdk1.7.0_51\
The second lies under the "System variables" section. You should find the "path" variable, and edit it. Then, append ";%JAVA_HOME%\bin" (minus the quotes) to the end of the path variable.
After you have done this, save the variables and close that window clicking the "ok" button. Close down all instances of the command prompt (and any IDE you may be developing with such as Eclipse or NetBeans), and reopen one command prompt. Then, if you would like to test whether or not your changes worked and are in effect, try the following:
echo %JAVA_HOME%
This should output where you set your java home variable to.
echo %PATH%
At the end of what is output, you should see your java home\bin addition to the path variable
java -version
If you can run this command from the command line, it means that your environment was set up correctly and java is now in your path.
Not necessary. Quit and Open the command prompt again (if any) that runs the java process and type java -version to check if it installed successfully.
If you are using mac, source ~/.bashrc or source ~/.zshrc should refresh your environmental variable. No need to re-start the terminal even.
No, you don't need to restart your system.
However, you have to restart your command prompt application to update the changes done on Environment variables.
NO.
You don't need to restart the system, but just the application like cmd or any IDE you are using for java development (i.e Eclipse) need to restart.
And to confirm that the java path is set that you have mentioned in JAVA_HOME environment variable, you can open cmd and you can check with commands echo %JAVA_HOME% or echo %PATH%.
I reinstall the JDK and set the JAVA_HOME and PATH variable again. now it's working.
In my case under user variable section(for particularuser) JAVA_HOME set to jre not jdk path . I change it to JDK path , It worked for me
yes need to restart cmd prompt after env variable change
Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.
In macOS X 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique.
Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home in your path add it like this.
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
References:
Oracle explains the java_home command
An article for configuring the JDK in Spring Tool Suite (Eclipse
2019) on MacOS
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in
$ echo $JAVA_HOME
it shows
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test
$ which java
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.
That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.)
Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here:
Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #hygull method
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
This method tested working in macOS Mojave Version 10.14.6.
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my .bash_profile:
export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
As other answers note, the correct way to find the Java home directory is to use /usr/libexec/java_home.
The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
For me maven seems to work off the .mavenrc file:
echo "export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" > ~/.mavenrc
I'm sure I picked it up on SO too, just can't remember where.
Create file ~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v 1.8)
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
For Fish Shell users, use something like the following: alias java7 "set -gx JAVA_HOME (/usr/libexec/java_home -v1.7)"