美文网首页Mac
mac安装jenv(java版本控制器)

mac安装jenv(java版本控制器)

作者: 毛豆豆豆豆子 | 来源:发表于2019-01-02 10:41 被阅读0次

    安装homebrew(默认您没安装)

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    安装jenv

    brew install jenv
    

    设置环境变量

    echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    echo 'eval "$(jenv init -)"' >> ~/.bash_profile
    

    查看是否安装成功

     jenv
    

    显示结果如下表示安装成功

    jenv 0.4.4
    Usage: jenv <command> [<args>]
    
    Some useful jenv commands are:
       commands    List all available jenv commands
       local       Set or show the local application-specific Java version
       global      Set or show the global Java version
       shell       Set or show the shell-specific Java version
       rehash      Rehash jenv shims (run this after installing executables)
       version     Show the current Java version and its origin
       versions    List all Java versions available to jenv
       which       Display the full path to an executable
       whence      List all Java versions that contain the given executable
    
    See `jenv help <command>' for information on a specific command.
    For full documentation, see: https://github.com/hikage/jenv#readme
    

    将现有的jdk添加到jenv管理

    jenv add /Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home jdk1.8 added
    
    • 其实就是建立了一个软链接等价于下面的命令
    cd ~/.jenv/versions/
    ln -s /Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home jdk1.8
    

    tips: macos的jdk和linux的jdk不一样mac的就得用os的jdk否则会报错如下

    cannot execute binary file //无法执行二进制文件
    

    查看现有的版本

    $ jenv versions
      system
    * jdk1.8 (set by /Users/zhangfei/.jenv/versions/.java-version)
    

    *代表当前使用中的版本

    切换java版本

    jenv local jdk11
    

    设置全局

    jenv global jdk11
    

    相关文章

      网友评论

        本文标题:mac安装jenv(java版本控制器)

        本文链接:https://www.haomeiwen.com/subject/cofalqtx.html