Configure JDK environment under mac

1. Download and install

Download address: Java Downloads | Oracle , select the JDK version suitable for Mac OS, and click to download.
After downloading, install directly:


The installation process is very simple, just press the "Continue" button and continue to the next step.

2. Configure environment variables

        In the previous step, in fact, we just copied the JDK1.8 files to the operating system. But if we want to use JAVA commands on the terminal, we also need to configure the system's environment variables.

        First of all, we need to know where the JDK directory is installed. If you install it through the above method, as long as you have not changed the installation path yourself, normal JDK1.8 is installed in the /Library/Java/JavaVirtualMachines directory. We can verify it in the following two ways. Down

After confirming that the directory is OK, you can start configuring the environment variable file. Open the configuration file through open ~/.bash_profile (if the terminal is zsh, use open ~/.zshrc), and then enter the following content in it:

#中间的jdk1.8.0那里记得换成你自己下载的那个版本
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_xxxxx.jdk/Contents/Home 

After configuring, save the file and exit.

3. Verify whether JDK1.8 is installed successfully.

        Open the Terminal. If your terminal is already open when saving the configuration file, remember to restart the terminal, or reload the terminal through the source ~/.bash_profile command, and then enter the following command to check whether the JDK is installed on the machine. :

java -version # 检查JDK版本

/usr/libexec/java_home -V # 列出所有JDK版本的JAVA_HOME

If I enter the first item and the version information of java appears, it means that the installation has been successful.

Guess you like

Origin blog.csdn.net/weixin_65784341/article/details/132581918