Apple Computer | macOS | jdk1.8 | Environment variable configuration

jdk download

Hello everyone, I believe many friends are like me. After changing to an Apple computer, many things need to be downloaded again, and jdk is the software that we Java programmers need most. However, due to the difference between macOS and Windows systems, We are not very familiar with it, especially in environment variable configuration; so, next, let me take you through it! Hope it could help everyone!

Among the jdk versions we use, jdk1.8 is the most commonly used version, so we take jdk8 download as an example to demonstrate downloading jdk on Apple macOS!

  • First, we first log in to the official website Oracle (click the link to enter, or directly search the oracle official website and enter)
  • 1. Enter the official website, click Products, and continue to click java (refer to the red arrow in the picture)

  • 2. Click to download java

  • 3. Click the third button here

  • 4. Scroll down and find java8

  • 5. Scroll down, find the mac version, and click on the blue and black font to download.

  • 6. Then follow the steps to complete the download!
    • There may be a small bug here. An installation error will be displayed during installation. In fact, you don’t need to worry about it, as long as it succeeds in the verification below.
    • Verify successful installation
      • If the Java version appears, it means the installation is successful.
      • Enter in the terminaljava -version

 Environment variable configuration

  • 1. Open the terminal and enter: /usr/libexec/java_home -V (note that V is capitalized)
    • Get the java download path here , be careful to save the one in the red box, we will use it later

  • 2. Enter in the terminal: touch .bash_profile to create a new configuration file (if you have used it before, you can skip this step)
  • 3. open -e .bash_profile opens the configuration file
    • A window will pop up. We enter the jdk environment variable template below.
  • 4. jdk environment variable template, just enter it and close it
#JAVA
JAVA_HOME=我的jdk路径
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH

  • 5. Source ~/.bash_profile takes effect in the configuration file to make the environment effective

At this point we have configured it. Finally, if we want to verify whether the configuration is successful, we can check it according to the following steps

  • At this time, if our environment variables are configured correctly, the java environment will become global, which means that we can find java in any folder.
  • So we open the terminal of any file (right-click the folder and select "New Terminal Window in the Folder" to open the terminal of any file), then enter, if the Java version appears (the same as where the jdk is installed), java -versionthen It shows that our environment is ready

Guess you like

Origin blog.csdn.net/m0_61780691/article/details/132194075