Pretty new to Java and also to Mac ... I want to make sure JAVA_HOME is set so in other programs I can use its path. So I did some Googling and here is what I got:
If I enter /usr/libexec/java_home in terminal I get this: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home but if I enter echo $JAVA_HOME in terminal, I don't get anything back.
Can you please tell me what is going on in here?
Thanks.
Verify JAVA_HOMEOpen a Command Prompt window (Win⊞ + R, type cmd, hit Enter). Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly.
JAVA_HOME is used by the launcher for finding the JDK/JRE to use. (JDK is recommended as some tasks require the java tools.)
In short, these export commands will automatically update JAVA_HOME variable as you re-install/upgrade your JDK/JRE packages or change default Java version. No need to adjust JAVA_HOME manually.
JAVA_HOME isn't set by default on OSX. You can resolve this by opening terminal and executing the following:
echo "export JAVA_HOME=`/usr/libexec/java_home`" >> ~/.profile . ~/.profile
This will cause JAVA_HOME to be set on startup (rather than just the current session), and immediately add it.
Try running source .bash_profile
prior to echo $JAVA_HOME
in your root directory. This should correct the problem if you've set JAVA_HOME
correctly. If you're not sure you're in your root directory, simply type cd ~
, press enter and you're there.
source
loads and runs your bash_profile.If you haven't set JAVA_HOME
correctly, following the instructions below should clear things up.
vim .bash_profile
— opens your bash_profile in Vim. I've included a list of VIM commands you'll likely need to edit your .bash_profile below.
export JAVA_HOME=$(/usr/libexec/java_home)
— creates an ENV_VAR (Environment Variable) and sets/stores the home path of the JDK to (/usr/libexec/java_home)
.source .bash_profile
— loads and runs your updated bash_profile echo $JAVA_HOME
— returns the value stored in the ENV_VAR JAVA_HOME
, which is the home path of your JDK installation. VIM Commands:
Vim is an editor to create or edit a text file. There are two modes in vim.
Command Mode: user can move around the file, delete text, etc.
Insert Mode: user can insert text.
Changing between modes:
Command mode to Insert mode
- type the appropriate letter for the action you want (a, A, i, I, o, O) -- details for letters below.
Insert mode to Command mode
- press Esc (escape key)
Text Entry Commands (Used to start text entry)
a -- Append text following current cursor position
A -- Append text to the end of current line
i -- Insert text before the current cursor position
I -- Insert text at the beginning of the cursor line
o -- Open up a new line following the current line and add text there
O -- Open up a new line in front of the current line and add text there
Cursor Movement Commands (only used in the commands mode.)
h -- Moves the cursor one character to the left
l -- Moves the cursor one character to the right
k -- Moves the cursor up one line
j -- Moves the cursor down one line
nG or :n -- Cursor goes to the specified (n) line
(ex. 10G goes to line 10)
$ -- Move cursor to the end of current line
0 -- (zero) Move cursor to the beginning of current line
w -- Forward one word
b -- Backward one word
Exit Commands
:wq -- Write file to disk and quit the editor
:q! -- Quit (no warning)
:q -- Quit (a warning is printed if a modified file has not been saved)
ZZ -- Save workspace and quit the editor (same as :wq)
VIM Editor Commands -- full list
osxterminaljava
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With