1

I am new to this mac world. I just installed jdk 8 on my mac and want to set $JAVA_HOME environment variable. I guess I should set it in .bash_profile file.

but it seems, my machine does not have this file and I don't know from where this $PATH variable coming from. Can't I have all env variables listed in one window or by one command just like windows?

how do I do it?

Thanks

2 Answers 2

2

Take a look at .bash_profile under your user directory - e.g. on my machine it's /Users/mikep/.bash_profile - if it doesn't exist, feel free to create it.

Here I assign environmental variables using export - e.g.

export JAVA_HOME=/Pathtomyjavainstall

export PATH=$PATH:/PathtomyJDKbindirectory

Then execute:

source ~/.bash_profile

To reload the environmental variables.

To check that they're set you can use echo from a Terminal window - e.g.

echo $JAVA_HOME

Results in: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

Sign up to request clarification or add additional context in comments.

2 Comments

so if /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home is the output I receive after executing ls -l which java, then both the params "Pathtomyjavainstall" and "PathtomyJDKbindirectory" should be the same path that I mentioned above right?
Path to my java install would be this - correct. JDK bin directory would be the /bin directory under Home - so: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin
0

If you do not see a .bash_profile in your home directory ($HOME or ~) when you do an ls -a, you should have a .profile which isn't bash-specific; but does the same job (execute on startup)

To see all the environment variables, just type set into the terminal. Or set|less if the list is too long.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.