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

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

问题描述

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

I just purchased a brand new MacBook Pro.

这是我有史以来的第一个MAC,我仍在尝试摆脱导航的束缚.

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

无论如何,我也是Java的新手,在Windows PC永久失效之前我一直在练习.

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

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

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

我不知道该怎么办.

我尝试遵循其中一些指南,但并没有走很远.

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

  1. YouTube:如何在Mac,Linux,Solaris上设置环境变量,rhel

    YouTube:如何在Mac中设置环境变量

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

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

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

    (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)对该文件的编辑会话崩溃. 在这种情况下,请使用:recover"或"vim -r/Users/Erwin/.bash_profile" 恢复更改(请参阅:help恢复"). 如果您已经这样做,请删除交换文件"/Users/Erwin/.bash_profile.sw p" 避免出现此消息.

    (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.

    有人可以逐步介绍如何在Mac OSX环境中设置Java吗?

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

    推荐答案

    从字面上看,您要做的就是:

    Literally all you have to do is:

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

    然后重新启动外壳程序.

    and restart your shell.

    如果您安装了多个JDK版本,并且希望将其作为特定版本,则可以像下面这样使用-v标志来标记java_home:

    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天全站免登陆