Перейти к содержимому

Как найти java на mac

  • автор:

How to Install Java on Mac

Ransomware recovery test drive: This technical workshop is designed to take you behind the scenes and shows you how to adopt strategies to automate recovery, ensuring you’re ready to become a recovery hero. REQUEST YOUR LAB

Table of Contents

Unsure how to install Java on Mac? As a developer, having different programming languages, like Java, installed on your computer is crucial. Java, one of the most popular programming languages, lets you develop web, mobile, and desktop applications.

In this tutorial, you will learn to install Java on a Mac in many ways and create a simple project to get you started in your Java journey.

Read on to expand your programming language repertoire!

Prerequisite

This tutorial comprises of hands-on demonstration. To follow along, ensure you have the following:

A Mac computer – This tutorial uses Big Sur, but any Mac running macOS 11.0 or higher will work.

A code editor – This tutorial uses Visual Studio Code (VS Code), but any code editor will work.

Using Homebrew to Install Java on Mac

One of the many ways you can install Java on Mac is by using Homebrew, a package manager for macOS. Homebrew lets you quickly install various software, like Java, on your Mac with a few commands.

Homebrew is the right package manager for you if you are more of a command-line person. And in this tutorial, you will install the latest and old/specific versions of Java on Mac.

Installing the Latest Version

Installing multiple versions of Java on your Mac works without any conflict. But the latest version is always recommended as it contains the latest security updates.

To install the latest version of Java on your Mac:

1. Run the below brew update command to update Homebrew.

Updating Homebrew

Updating Homebrew

2. Next, run the following command to search for the available java formula. Homebrew uses formulas to manage packages and applications.

You can see below that there are many versions of Java available. The java formula is the alias for the most recent release.

Searching for the available Java formula

Searching for the available Java formula

3. Run the below command to get detailed information (info) about the java formula.

As you can see below, at this time of writing, the latest Java release is 19, which is not installed yet.

Getting detailed information about the java formula

Getting detailed information about the java formula

4. Now, run the following brew install command to install java on your Mac.

Installing the latest Java release

Installing the latest Java release

5. Once installed, run the below ln command to create a symbolic link (symlink) that points to the installed Java version.

In the command below, the following paths are as follows:

  • /usr/local/opt/openjdk/libexec/openjdk.jdk – The created symlink.
  • /Library/Java/JavaVirtualMachines/openjdk.jdk – The path where the symlink points to.

Creating a symlink is necessary as some applications only work correctly if they can find a Java installation in the standard location.

Enter your password when prompted to complete the process.

Creating a symlink for Java

Creating a symlink for Java

6. Finally, run the below command to print the installed Java version.

The output below confirms you have successfully installed the latest version of Java on your Mac, where:

  • OpenJDK is an open-source implementation of the Java platform.
  • JDK is the Java Development Kit, a set of tools for developing Java applications.

Congratulations! You have successfully installed the latest Java release on your Mac.

Checking the installed Java version

Checking the installed Java version

Installing an Older or a Specific Version

The latest version of your Java installation should be fine and all. But “version compatibility” is a thing when building or developing programs. The good news is that you can install older or specific versions of Java alongside other versions.

To install an older or a specific Java version, you first have to find the available ones:

1. Run the below command to search the openjdk formula for all available Java versions. This formula usually contains much older versions of Java than the java formula.

Pick one from the available versions below ([email protected], 11, and 17) that you wish to install.

�� The [email protected] is the newest LTS version, and some applications might not support it yet.

Searching for available Java versions

Searching for available Java versions

2. Next, run the below command to install a specific Java version, replacing <java_version> with your preferred one.

As you see below, this tutorial’s choice is the [email protected] version since [email protected] is too old and is not recommended anymore.

Installing an older version of Java

Installing an older version of Java

3. Once the installation completes, run the below command, which does not provide output but creates a symlink.

4. Finally, run the exact java command below to verify the version of your Java installation.

Verifying the installed Java version

Verifying the installed Java version

Installing Java via the DMG Package

If you fancy a GUI instead of a command-line environment, you want to try installing Java with a DMG package (a disk image file). A DMG package acts as a virtual optical disc containing compressed software installation files and other data like bootable images.

Installing Java via a DMG package is a little bit more manual work. But hey, clicking through a basic installation wizard would not hurt.

1. Open your favorite web browser, and navigate to Oracle’s official Java downloads page.

2. Next, click on the DMG link for the JDK version you want to install to download its DMG package to your Downloads directory. The tutorial goes with Java 19, the latest version at the time of this writing.

Downloading Java’s DMG package

Downloading Java’s DMG package

3. Once downloaded, double-click the DMG file to launch the installer.

Launching the Java installer

Launching the Java installer

4. On the Introduction tab, click Continue to acknowledge the welcome page.

Acknowledging the welcome page

Acknowledging the welcome page

5. Now, click Install to the installation process.

Installing Java on Mac

Installing Java on Mac

6. Enter your password when prompted and click Install Software to authorize the installation.

Authorizing the installation

Authorizing the installation

7. Once installed, click Close to close the installation wizard.

And that is it! You have now successfully installed Java on your Mac via the DMG package.

Click Close to close the installer.

Click Close to close the installer.

8. Finally, run the below command for the last time to check the installed Java version.

Verifying the installation

Verifying the installation

Switching Between Java Versions

Suppose one project requires Java 11, but another requires Java 19. If so, how do you switch between the two Java versions? Worry not! You can work on different Java versions, switching between each, on your Mac at will.

To switch between Java versions:

1. Run the below command to find out the available versions of Java installed on your computer.

Pick one version you want to switch to, as shown below.

Listing all available versions of Java

Listing all available versions of Java

2. Next, run the below command to find the current default Java version.

As you can see below, Oracle JDK 19 is currently the active or default Java version.

Finding the current default Java version

Finding the current default Java version

3. Run the below echo command to find the current shell ($SHELL).

Notice in the output below that this tutorial uses the ZSH shell.

Finding the current shell

Finding the current shell

4. Now, run the below command to switch to a different Java version, replacing <version> with your preferred version.

These commands perform the following:

  • export the path of a specific Java version to the JAVA_HOME environment variable, which tells Java to use the version you specified.
  • source the profile and apply the changes.

�� Perhaps you are on a Bash shell. If so, run the source

/.bashrc command instead to source the profile.

�� Switching to another Java version does not provide output, but you will later verify if the switch is a success.

5. Finally, run the below commands to verify the current Java -version.

The output below confirms the version switch is a success, as the current version is set to OpenJDK 11.

Verifying the version switch

Verifying the version switch

Creating Your First Java Project on Mac

Successfully installing Java and switching between versions do not tell if Java is working correctly. How do you test if Java works on your Mac? You will create a basic “hello world” program and use Java to compile and run the program.

To create a Java project:

1. Run the following commands to create a directory (mkdir) for your project (hello-world), and change the working directory (cd) into that directory.

These commands do not provide output, but you will verify the project files in the following steps.

2. Next, create a file named HelloWorld.java in your preferred code editor, add the code below to the file, save the changes and close the file.

The code below is a simple Java program that prints the Hello World message to the console.

3. Run the following javac command, which does not provide output, but compiles your program (HelloWorld.java).

4. Now, run the command below to list (ls) all contents (-la) of the working directory (

You will see a new file named Hello.class is generated, as shown below. This file contains the bytecode for your program.

Verifying the project files

Verifying the project files

5. Lastly, execute the below command to run your program (Hello).

This command calls the Java Runtime Environment to execute your program, where the Hello class is loaded, and the main method is executed.

The output below confirms that your program is working as expected and your Java installation is successful.

Running the Java program

Running the Java program

Conclusion

In this tutorial, you have learned many ways how to install Java on Mac and create a simple Java project. Java is one of the most popular programming languages in the world. Every nook and corner of the tech industry uses Java in some way or the other.

And at this point, you can now confidently build your projects. Moreover, since you can quickly switch between versions, you never have to worry about version compatibility.

With this newfound knowledge, why not build your own Java application and see how it works?

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

More from ATA Learning & Partners

Recommended Resources!

Recommended Resources for Training, Information Security, Automation, and more!

Get Paid to Write!

ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

ATA Learning Guidebooks

ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!

Where is Java Installed on Mac OS X?

I downloaded Java 7u17 on Mac OS 10.7.5 from here and successfully installed it. To do some JNI programming, I need to know where Java is installed on my Mac.

I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but then I found the folder empty. This was confirmed by running ls /Library/Java/JavaVirtualMachines/ in the Terminal. I’ve tried searching for it to find out if it was installed somewhere, but that doesn’t seem to be turning anything up.

Как запускать файлы JAR на Mac

Трекпад не работает после установки macOS Monterey

В этой статье мы объяснили пошаговый процесс запуска файлов JAR на вашем устройстве Mac.

JAR — это формат файла пакета, который представляет собой набор файлов классов Java, связанных метаданных и других ресурсов, объединенных в один файл. Если вы разбираетесь в технологиях и часто пользуетесь Интернетом, вы, вероятно, столкнетесь с файлами JAR. Иногда вам может понадобиться запустить эти файлы, но, в отличие от Windows 11, распаковать файлы .jar на Mac непросто.

Это связано с тем, что в Mac нет встроенных программ, которые могут распаковывать или выполнять эти файлы.
Чтобы помочь вам запускать файлы .jar на Mac, вы решили составить это подробное руководство, в котором объясняется весь процесс запуска файлов .jar.

Итак, давайте закончим болтовню и перейдем сразу к делу!

ЗАПУСК JAR-ФАЙЛОВ НА MAC

Проверьте, есть ли на вашем Mac Java

Для непосвященных, чтобы запускать файлы JAR, вы должны убедиться, что Java предварительно установлена ​​на вашем Mac. И JRE (Java Runtime Environment), и JDK (Java Development Kit) могут быть совместимыми программами. Выполните следующие действия, чтобы узнать, присутствует ли Java на вашем Mac.

Как запускать файлы JAR на Mac - rdd.media 2023

  • Если Java не установлена ​​на вашем Mac, вы получите сообщение о том, что «Среда выполнения Java отсутствует, требуется сообщение об установке».
  • Теперь нажмите кнопку OK во всплывающем окне.
  • Если JDK/JRE уже установлен на вашем Mac, вы увидите его версию.

Загрузите Java на свой Mac

Если Java еще не установлена ​​на вашем Mac, вам необходимо установить ее на свой Mac. Если на вашем Mac уже установлена ​​Java, пропустите этот шаг. Итак, начнем:

  • Прежде всего, вам нужно запустить браузер Safari на вашем Mac.
  • Теперь посетите официальный сайт Oracle.
  • Вы попадете на страницу загрузки последней версии Java. Чтобы просмотреть все доступные пакеты для разных ОС, продолжайте прокручивать.
  • Чтобы загрузить Java для своего Mac, перейдите на вкладку macOS.
  • Найдите ссылку на установщик .dmg под столбцом «Загрузить».
  • Установите флажок перед сообщением «Я ознакомился и принимаю лицензионное соглашение Oracle Technology Network для Oracle Java SE» и нажмите кнопку «Загрузить» для подтверждения.
  • В открывшемся всплывающем окне выберите параметр «Сохранить файл» и нажмите кнопку «ОК».
  • Подождите, пока файл не загрузится на ваш Mac. Скорость загрузки будет зависеть от скорости вашего интернет-соединения.

Установите файл Java

Теперь вам нужно установить файл .dmg на свой Mac. Вам нужно будет разрешить Mac устанавливать файлы, отличные от Apple, для его установки.
Давайте посмотрим, как вы можете дать разрешение Apple:

  • Нажмите на значок Apple, а затем выберите «Системные настройки».
  • Теперь выберите опцию «Безопасность и конфиденциальность».
  • Перейдите на вкладку «Общие» и нажмите значок блокировки в левом нижнем углу.
  • Введите свой пароль и нажмите Открыть в любом случае.
  • Еще раз нажмите кнопку «Открыть» для подтверждения.

Давайте начнем устанавливать установочный файл Java на ваш Mac:

  • Прежде всего, перейдите в папку «Загрузки» и найдите файл .dmg.
  • Дважды щелкните, чтобы запустить файл. Появится папка с файлом Java .pkg. Дважды щелкните его.
  • Откроется мастер установки.
  • Нажмите «Продолжить», а затем кнопку «Установить».

Запуск файлов JAR на Mac

  • Введите свой пароль и нажмите кнопку «Установить программное обеспечение», чтобы начать процесс установки.
  • Когда файл будет установлен, на экране появится сообщение о том, что установка выполнена успешно.
  • Нажмите кнопку Закрыть.

Запуск файлов .jar на Mac

Теперь, когда Java успешно установлена ​​на вашем Mac, пришло время запустить файлы JAR. Вы можете либо перейти к месту, где находится файл JAR, либо выполнить файлы через окно терминала.
Давайте посмотрим, как запустить файлы JAR из папки:

Как запускать файлы JAR на Mac - rdd.media 2023

  • Прежде всего, щелкните значок Finder на панели Dock.
  • Теперь выберите вариант приложения на левой боковой панели.
  • Теперь выберите «Утилиты», а затем «Окно терминала».
  • Когда на вашем Mac откроется окно терминала, введите следующую команду.
  • Вам нужно заменить атрибут FILENAME именем файла JAR.
    java -jar ИМЯ ФАЙЛА.jar
Вывод

Это все в этом руководстве. Если вы будете внимательно следовать инструкциям, вы сможете без проблем установить файлы JAR на свой Mac. Если у вас возникнут трудности с запуском файлов JAR, вы можете обновить версию JAVA на своем Mac.

2022. Setting up Java Development Environment on Mac JDK, Tomcat, and Eclipse

Install JDK, Apache Tomcat and Eclipse on Mac.

We will use the following free softwares/tools.

  • JDK — Java SE Development Kit, a free integrated development kit used to build, test, and deploy Java applications.
  • Apache Tomcat — An open source web server.
  • Eclipse — One of the most widely used Java IDEs.

1. Installing JDK on Mac

1.1 Downloading Oracle JDK

Download the latest version of JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Select JDK, in the next page, accept the license and choose ‘jdk-8u151-macosx-x64.dmg’ to download.

1.2 Installing JDK

installjdk

After downloading finish, double click on the installer. Follow the wizard to install JDK.
Finally, JDK is installed to /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/.

1.3 Checking Java Version

You should be able to see the java information like below.

2. Setting up Apache Tomcat

2.1 Downloading Tomcat

Download the latest version of Tomcat from https://tomcat.apache.org/.

2.2 Installing Tomcat

There is no installer, have to configure Tomcat manually. Unzip the tar file, copy to /opt/tomcat.

Create a symbolic link that we are going to use when referring to Tomcat

Change ownership of the /Library/Tomcat folder hierarchy:

Make all scripts executable:

2.3 Starting Tomcat

Using the following commands to start and stop tomcat:

Verify that Tomcat is working by visiting http://localhost:8080. tomcat

3. Installing Eclipse

3.1 Downloading Eclipse

Download the latest version of Eclipse from https://www.eclipse.org/downloads/.

3.2 Installing Eclipse

1) Unzip the tar file. You will get one installer file named ‘Eclipse Installer’.

eclipseinstaller

2) Double click on ‘Eclipse Installer’. Select ‘Eclipse IDE for Java EE Developers’.
Follow the wizard to finish the installation.

3.3 Starting Eclipse

Eclipse is installed to ‘/Users/ /eclipse/jee-oxygen’, run following command to launch Eclipse.

Set workspace. eclipseworkspace
Close the welcome page, you will get Eclipse ready for use. eclipselaunched

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *