Detailed steps for configuring Java development environment in macOS

Certain packages of the R language require a Java development environment. As a software novice, I encountered many problems when installing them on a Mac. This post is a compilation of my own installation process. The operation is relatively detailed and very stupid. If you have any questions, please feel free to comment~

Reference is as follows:

Main process:Configuring Java development environment in Mac environment (jdk maven tomcat idea) - Zhihu

maven installation: https://blog.csdn.net/m0_67401920/article/details/123656813

Model and system version:

1. Download and install JDK

1) Installation address (official website):Java Downloads | Oracleicon-default.png?t=N7T8https://www.oracle.com/java/technologies/downloads /#jdk21-mac

After downloading, double-click the dmg file and keep pressing "Continue" to install it.

JDK files for mac are generally installed in: /Library/Java/JavaVirtualMachines (Hard Disk-Resource Library-Java-JavaVirtualMachines)

2. Configure JDK

1) Search for "terminal" on the launcher and enter the terminal app (similar to the cmd command line of win system).

2) Enter the terminal and enter: vim ~/.bash_profile Press Enter to enter the editing mode.

(If you need a password, just enter the power-on password and press Enter. It doesn’t matter if the cursor doesn’t respond. It looks like you didn’t enter it but you actually entered it)

3) Switch to the English input method, type i, and enter insert mode.

4) Enter the following:

JAVAHOME=/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home

PATH=$JAVAHOME/bin:$PATH:.

CLASSPATH=JAVAHOME/lib/tools.jar:$JAVAHOME/lib/dt.jar:.

export JAVA_HOME

export PATH

export CLASSPATH

It is mentioned in the original link: Maybe you do not have write permissions for bash_profile. You will be prompted when saving. Remember to add sudo before the command. (But I didn't encounter this problem)

5) Press the Esc key to exit the editing mode, enter :wq to save and exit.

6) Enterjava -version in the terminal (note that there is a space before "-version"). The following pop-up will indicate that the configuration is complete.

3. Download and configure maven

1) Download the site (official):Maven – Download Apache Mavenicon-default.png?t=N7T8https://maven.apache.org/download.cgi< /span>

2) After decompressing, place the file where you want it to be

3) Enter edit-insert mode again in the terminal, enter the following content, and add the command to set environment variables in the .bash_profile file

export M2_HOME=mavenFolder path (note that the path must be in English and cannot contain Chinese)

export PATH=$PATH:$M2_HOME/bin

4) Press the Esc key to exit the editing mode, enter:wqSave and exit

5) Entermvn -version in the terminal (note that there is a space before "-version"). The following content will pop up to indicate that the configuration is complete. .

4. Download and configure tomcat

1) Download address (official website):Apache Tomcat® - Apache Tomcat 9 Software Downloadsicon-default.png?t=N7T8https://tomcat.apache.org/ download-90.cgi

2) After decompressing, place the file in the library (resource library) and rename it to Tomcat. (It may work if you put it in other places, but if I put it in other places, an error will occur during startup, so refer to ​​​​​​Mac system installation Tomcat terminal appears -bash: startup. sh: command not found - Jianshu, put the file in the library)

3) Enter in the terminal: vim ~/.bash_profile and press Enter to enter the editing mode. Enter the following:

export PATH=$PATH:/Library/Tomcat/bin

4) Press the Esc key to exit the editing mode, enter :wq to save and exit.

5) If you enter startup.sh directly in the terminal at this time, command not found or Permission denied will pop up. The solution is as follows:

        a) Entersudo chmod 755 /Library/Tomcat/bin/*.sh. At this time, the terminal will prompt you to enter the password and enter to boot. Password is enough.

        b) 继续输入cd /Library/Tomcat/bin/,进入bin目录

        c) Continue to entersudo sh startup.sh, and then the terminal will display:

Indicates that the Tomcat server is started.

6) Verification method: Enterlocalhost:8080 in the browser. If the following picture appears, it means the installation is successful.

Or entersh /Library/Tomcat/bin/catalina.sh versionViewTomcat, the following content indicates success. version

8) If you need to shut down: enter in the terminalshutdown.sh 

5. Download and configure IDEA

下载链接(官网):Download IntelliJ IDEA – The Leading Java and Kotlin IDEDownload the latest version of IntelliJ IDEA for Windows, macOS or Linux.icon-default.png?t=N7T8https://www.jetbrains.com/idea/download/?section=mac#section=mac

There is a community version (free) and a flagship version (paid). It is best to download the flagship version. After downloading, activate the software. You can purchase it if you have conditions. If not, use Baidu or Moubao.

After the above is completed, the Java development environment is configured!

Then open Rstudio and call the package that requires the Java development environment, and no error will be reported.

Guess you like

Origin blog.csdn.net/Mymm_id/article/details/134063137