- Настройка среды разработки Java для Mac OS
- Установите brew
- Установить java
- Используйте несколько версий java на одной машине
- Установите jenv и настройте
- Команды Jenv
- Установите JAVA_HOME
- Настройка глобальных пакетов SDK в Intellij
- Java mac os настройка
- System Requirements for Installing the JDK on macOS
- JDK Installation Instruction Notation for macOS
- Determining the Default JDK Version on macOS
- Installing the JDK on macOS
- Uninstalling the JDK on macOS
- Installation FAQ for macOS
Настройка среды разработки Java для Mac OS
Как настроить среду разработки java. С тегами setup, java, brew, jenv.
Я некоторое время гуглил “как установить java 8 на macOS”, но это не очень помогает мне понять, как на самом деле установить java 8 на мой MacBook. Некоторые учебники устарели. Поэтому я решил написать учебник по настройке среды разработки java в macOS, который охватывает все, что вам нужно для настройки, и как использовать несколько версий java на одной машине, как переключить java с версии 8 на 13 и т.д.
Установите brew
Откройте терминал или iTerm и вставьте эту строку, чтобы установить brew.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Установить java
$ brew tap adoptopenjdk/openjdk # javc 8 $ brew install --cask adoptopenjdk8 # java 11 $ brew install --cask adoptopenjdk11 # gradle $ brew install gradle # maven $ brew install maven
Используйте несколько версий java на одной машине
Если вы хотите использовать другие версии java на той же машине, вместо установки JAVA_HOME каждый раз, когда вы запускаете терминал, мы будем использовать jenv для переключения между версиями и выполнять настройку пути для вас.
Установите jenv и настройте
Добавить домашнюю папку java в jenv
$ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home $ jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Команды Jenv
➜ ~ jenv jenv 0.5.2 Usage: jenv [] 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 ' for information on a specific command. For full documentation, see: https://github.com/hikage/jenv#readme
список версий с версиями jenv
➜ ~ jenv versions * system (set by /Users//.jenv/version) 1.8 1.8.0.222 11.0 11.0.4 openjdk64-1.8.0.222 openjdk64-11.0.4
переключение между версиями
использование оболочка jenv openjdk 64-1.8.0.222#или openjdk 64-11.0.4
➜ ~ java -version openjdk version "1.8.0_222" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.222-b10, mixed mode) ➜ ~ jenv versions system 1.8 1.8.0.222 11.0 11.0.4 * openjdk64-1.8.0.222 (set by JENV_VERSION environment variable) openjdk64-11.0.4 ➜ ~ jenv shell openjdk64-11.0.4 ➜ ~ java -version openjdk version "11.0.4" 2019-07-16 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode) ➜ ~ jenv versions system 1.8 1.8.0.222 11.0 11.0.4 openjdk64-1.8.0.222 * openjdk64-11.0.4 (set by JENV_VERSION environment variable)
Установите версию java по умолчанию в /Пользователи//.jenv/версия и содержимое будет той версией java, которую вы хотите использовать, сохраните файл и запустите новую оболочку, будет установлена версия java по умолчанию, которую вы написали в файле.
➜ ~ jenv versions system 1.8 1.8.0.222 11.0 11.0.4 * openjdk64-1.8.0.222 (set by /Users/ayuth/.jenv/version) openjdk64-11.0.4
Установите JAVA_HOME
Если JAVA_HOME не найден. Просто используйте плагин экспорта jenv плагина.
➜ ~ echo $JAVA_HOME ➜ ~ jenv enable-plugin export # -------- restart your shell session -------- ➜ ~ echo $JAVA_HOME /Users/ayuth/.jenv/versions/1.8.0.242
Что еще более интересно, у них есть jenv enable-плагин maven и jenv включить-плагин gradle .
Настройка глобальных пакетов SDK в Intellij
Если вы хотите добавить установленные версии JDK в Intellij, вы можете перейти к чтению там: https://www.jetbrains.com/help/idea/sdk.html#manage_sdks .
- Откройте IntelliJ.
- В окне запуска нажмите “Настроить” в правом нижнем меню.
- Выберите “Структура для новых проектов”. Вы увидите открывающееся всплывающее окно под названием “Структура проекта для новых проектов”.
- В меню слева выберите “Настройки платформы” –> “SDK”.
- Нажмите кнопку “+”, чтобы добавить новый SDK, вы увидите раскрывающееся меню.
- Нажмите кнопку “Добавить JDK…”.
- Вы увидите окно поиска.
- Нажмите Command +Shift + G, чтобы открыть диалоговое окно перехода к пути и вставить /Библиотека/Java/Javavirtualmachines , а затем нажмите go.
- В окне finder вы увидите список версий JDK. Просто выберите версию JDK, которую вы хотите добавить, и нажмите “Открыть”.
- Вы увидите выбранный JDK в списке, что означает, что вы поступаете правильно.
Это все. Счастливого Взлома!
Java mac os настройка
The JDK supports both Intel-based (x64) and Apple Silicon (AArch64) Mac computers.
This topic includes the following sections:
System Requirements for Installing the JDK on macOS
JDK Installation Instruction Notation for macOS
JDK installers now support only one version of any Java feature release. You can’t install multiple versions of the same feature release.
For example, you can’t install jdk- 20 and jdk- 20 .0.1 simultaneously. If you attempt to install jdk- 20 .0.1 after jdk- 20 is installed, the installer uninstalls jdk- 20 and installs jdk- 20 .0.1 .
If you install an older version of a JDK when the newer version of the same feature family already exists, an error is displayed, prompting you to uninstall a newer JDK version if an older version has to be installed.
JDK is installed in /Library/Java/JavaVirtualMachines/jdk- .jdk where is the feature release number. For example, JDK 20 .0.1 is installed in /Library/Java/JavaVirtualMachines/jdk- 20 .jdk .
macOS aarch64 (64-bit ARM) systems:
jdk-20_macos-aarch64_bin.dmg
jdk-20_macos-aarch64_bin.tar.gz
Determining the Default JDK Version on macOS
When starting a Java application through the command line, the system uses the default JDK.
You can determine which version of the JDK is the default by entering java -version in a Terminal window. If the installed version is 20 Interim 0, Update 0, and Patch 0, then you see a string that includes the text 20 . For example:
$ java -version java version "20" Java(TM) SE Runtime Environment (build 20) Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
To run a different version of Java, either specify the full path, or use the java_home tool. For example:
$ /usr/libexec/java_home -v 20 —exec javac -version
Installing the JDK on macOS
- macOS x64 systems: jdk- _macos-x64_bin.dmg OR jdk- _macos-x64_bin.tar.gz
- macOS aarch64 (64-bit ARM) systems: jdk- _macos-aarch64_bin.dmg OR jdk- _macos-aarch64_bin.tar.gz
Click Accept License Agreement .
A window appears that displays the message: Installer is trying to install new software. Enter your password to allow this.
After the software is installed, you can delete the .dmg or .tar.gz file if you want to save disk space.
Uninstalling the JDK on macOS
Do not attempt to uninstall Java by removing the Java tools from /usr/bin . This directory is part of the system software and any changes will be reset by Apple the next time that you perform an update of the OS.
- Go to /Library/Java/JavaVirtualMachines .
- Remove the directory whose name matches the following format by executing the rm command as a root user or by using the sudo tool:
/Library/Java/JavaVirtualMachines/jdk- 20 . interim.update.patch .jdk For example, to uninstall 20 Interim 0 Update 0 Patch 0: $ rm -rf jdk- 20 .jdk
Installation FAQ for macOS
This topic provides answers for the following frequently asked questions about installing JDK on macOS computers.
1. How do I find out which version of Java is the system default?
When you run a Java application from the command line, it uses the default JDK. If you do not develop Java applications, then you do not need to worry about this. See Determining the Default JDK Version on macOS.
2. How do I uninstall Java?
3. After installing Java for macOS 2012-006, can I continue to use Apple’s Java 6 alongside the macOS JDK for Java 20 ?
If you want to continue to develop with Java 6 using command-line, then you can modify the startup script for your favorite command environment. For bash, use this:
$ export JAVA_HOME=`/usr/libexec/java_home -v 20 `
Some applications use /usr/bin/java to call Java. After installing Java for macOS 2012-006, /usr/bin/java will find the newest JDK installed, and will use that for all of the Java-related command-line tools in /usr/bin . You may need to modify those applications to find Java 6, or contact the developer for a newer version of the application.
4. What happened to the Java Preferences app in Application Utilities?
The Java Preferences app was part of the Apple Java installation and is not used by Oracle Java. Therefore, macOS releases from Apple that do not include Apple Java will not include Java Preferences.