add java to path mac code example
Example 1: how to add java_home in mac
1. Open terminal window
2. Type command: $ vim ~/.bash_profile and Hit Enter
3. Type command: $ export JAVA_HOME=$(/usr/libexec/java_home) and press Escape key for Save changes.
4. Type command: :(colon)wq, It will Save and close .bash_profile file.
5. Type command: source ~/.bash_profile and hit Enter
6. Now we can check the value of the JAVA_HOME variable:
7. Type Command: echo $JAVA_HOME
The result should be the path to the JDK installation:
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
Example 2: adding path in mac
The easiest way to add a new path to $PATH (the environment variable) is with the export command. In this example we’ll add “~/opt/bin” to the user PATH with export:
export PATH=$PATH:~/opt/bin
You can run that directly from the command line, then check the $PATH with echo to show that it has been added like so:
echo $PATH