Multiple versions of Java managed on Mac using jenv

Source: Internet
Author: User

Because the server is java1.7, the MAC is 1.8, so the Java code compiled by the MAC will escalate the error on the server. Therefore, need to modify the Java version of the Mac, their own toss for a long time, give up, decided to use JENV management! The result is very convenient

Steps to use:

1, installation Jenv

2. Install each version of Java

3. Set the Java path

4. Close the console and turn it back on (restart a new console after adding configuring the Jenv)

5. JENV Local * * * * (remember this command, often used.) The previous steps are once and for all. )

The following is reproduced, thanks to the original author.

http://boxingp.github.io/blog/2015/01/25/manage-multiple-versions-of-java-on-os-x/

Basic use:

Use homebrew to install jenv under Mac OS x:

1
$ brew install jenv

After the installation is successful, a simple configuration is required to make it work:

Use of Bash scenarios

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

Case of using zsh

12
$ echo ‘export PATH="$HOME/.jenv/bin:$PATH"‘ >> ~/.zshrc$ echo ‘eval "$(jenv init -)"‘ >> ~/.zshrc

OK, jenv is already installed, let's see which Java version it's looking for:

12
$ jenv versions* system (set by /Users/bxpeng/.jenv/version)

It only found the default Java for the system, even though I have downloaded other versions of Java. *represents the currently selected version.

Unlike rbenv, jenv cannot install any version of Java on its own, so we need to manually install it and then use jenv to point to them.

Java 6 is installed and needs to be downloaded from Apple. It will be installed to the /System/Library/Java/JavaVirtualMachines/ next; Java 7 is installed and can be downloaded from Oracle. It will be installed /Library/Java/JavaVirtualMachines/ under; Java 8 is installed and can be downloaded from Oracle. It will be installed to the /Library/Java/JavaVirtualMachines/ next.

Using Add jenv add Java 6 to jenv:

1234  
$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/1.6 added1.6.0.65 addedoracle64-1.6.0.65 added

The runtime jenv versions will display:

123)45   
$ jenv versions* system (set by /Users/bxpeng/.jenv/version) 1.6 1.6.0.65 oracle64-1.6.0.65

Similarly, use jenv add Java 7 to join Jenv:

1234     
 $ jenv add/library/java/ Javavirtualmachines/jdk1.7.0_71.jdk/contents/home/1.7 added1.7.0.71 added<
Span class= "line" >oracle64-1.7.0.71 added       
1234  
$ jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/1.8 added1.8.0.25 addedoracle64-1.8.0.25 added

Now the run jenv versions will show:

1234567891011            
$ jenv versions* system (set by /Users/bxpeng/.jenv/version) 1.6 1.6.0.65 oracle64-1.6.0.65 1.7 1.7.0.71 oracle64-1.7.0.71 1.8 1.8.0.25 oracle64-1.8.0.25

For bloggers who are not Virgo, they also feel the need to manage the version again, using the jenv remove unwanted Java version that can be removed from the jenv:

12
$ jenv remove 1.6JDK 1.6 removed

After finishing, the run jenv versions will show:

123)45   
$ jenv versions* system (set by /Users/bxpeng/.jenv/version) 1.6.0.65 1.7.0.71 1.8.0.25

Select a Java version to run jenv local , for example:

123)45   
$ jenv local 1.8.0.25$ java -versionjava version "1.8.0_25"Java(TM) SE Runtime Environment (build 1.8.0_25-b17)Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Dangdangdangdang, we have successfully specified a Java version of local in a folder.

You can run jenv global a default Java version and run the jenv which java full path that shows the executable java.

You can also use the. java-version file in a specific folder to set the Java version. When I need to use Java 6 o'clock in project, I just need to 1.6.0.65 save as content in the. java-version file, and when I go to that folder Jenv automatically helps me to set the Java version of Local.

Yes, we now have multiple versions of Java and can easily switch between them. More methods of use can be found on the official website of Jenv.

Multiple versions of Java managed on Mac using jenv

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.