如何在 Mac OS X 10.9 上设置 JAVA_HOME 环境变量? [英] How to set JAVA_HOME environment variable on Mac OS X 10.9?

查看:42
本文介绍了如何在 Mac OS X 10.9 上设置 JAVA_HOME 环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚购买了全新的 MacBook Pro.

这是我有史以来的第一个 MAC,我仍在努力掌握导航的窍门.

无论如何,我也是 Java 的新手,并且在它永久死亡之前我一直在我的 Windows PC 上练习.

现在我在这个 MAC 上,我安装了我的 JDK,现在我需要设置 JAVA_HOME 环境变量.

我不知道该怎么办.

我尝试遵循这些指南中的一些,但并没有走得太远.

  1. Mkyong.com : 如何在 Mac OSX 中设置 JAVA_HOME 变量

  2. YouTube:如何在 mac、linux、solaris、雷尔

  3. YouTube:如何在 Mac 中设置环境变量b>

我找到了终端,我想我创建了多个文件.我收到这样的消息:

<小时><块引用>

(1) 另一个程序可能正在编辑同一个文件.如果是这种情况,请注意不要以两个进行更改时同一文件的不同实例.退出,或谨慎继续.

<小时><块引用>

(2) 此文件的编辑会话崩溃.如果是这种情况,请使用 ":recover" 或 "vim -r/Users/Erwin/.bash_profile"恢复更改(参见:help recovery").如果您已经这样做了,请删除交换文件/Users/Erwin/.bash_profile.sw p"以避免此消息.

谁能告诉我如何在 Mac OSX 环境中逐步设置 Java?

解决方案

如果您使用的是 bash,您所要做的就是:

echo export "JAVA_HOME=$(/usr/libexec/java_home)";>>~/.bash_profile

如果您使用的是 zsh(这可能意味着您运行的是 macOS Catalina 或更新版本),那么它应该是:

echo export "JAVA_HOME=$(/usr/libexec/java_home)";>>~/.zshrc

无论哪种情况,请重新启动您的 shell.

如果您安装了多个 JDK 版本并且希望它是一个特定版本,您可以像这样使用 -v 标志来 java_home:

echo export "JAVA_HOME=$(/usr/libexec/java_home -v 1.7)";>>~/.bash_profile

I just purchased a brand new MacBook Pro.

This is my first MAC ever and I'm still trying to get the hang of navigating my way around.

Anyway, I'm also new to Java and I've been practicing on my Windows PC before it permanently died.

Now that I'm on this MAC, I installed my JDK and now I need to set the JAVA_HOME environment variable.

I have no idea what to do.

I tried following some of these guides and didn't get very far.

  1. Mkyong.com : How to set JAVA_HOME variable in Mac OSX

  2. YouTube : How to set environment variables on mac, linux, solaris, rhel

  3. YouTube : How to Set Environment Variables in Mac

I was able to locate the terminal and I think I created some multiple files. I'm getting messages like this:


(1) Another program may be editing the same file. If this is the case, be careful not to end up with two different instances of the same file when making changes. Quit, or continue with caution.


(2) An edit session for this file crashed. If this is the case, use ":recover" or "vim -r /Users/Erwin/.bash_profile" to recover the changes (see ":help recovery"). If you did this already, delete the swap file "/Users/Erwin/.bash_profile.sw p" to avoid this message.

Can somebody tell how to set Java in Mac OSX environment step by step?

解决方案

If you're using bash, all you have to do is:

echo export "JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.bash_profile

If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:

echo export "JAVA_HOME=$(/usr/libexec/java_home)" >> ~/.zshrc

In either case, restart your shell.

If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:

echo export "JAVA_HOME=$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile

这篇关于如何在 Mac OS X 10.9 上设置 JAVA_HOME 环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆