overview
This article installs jdk1.8 mainly in the following 4 steps:
- Download the installation package
- Install
- Configure environment variables
- Verify that the installation was successful
Download the installation package
Go to the jdk official website , find the installation package corresponding to your system and click to download, as shown in the figure below:
you must log in to the Oracle account to download the sdk, and if you don’t have one, you need to register one.
Install
After the installation package is downloaded, click the installation package, and then keep clicking 继续
to complete the installation.
Configure environment variables
After the installation is complete, we first need to find the jdk installation directory, usually the directory is /Library/Java/JavaVirtualMachines
, you can go to the directory to confirm the following. After confirmation, enter the home directory, that is /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
, configure this directory as an environment variable JAVA_HOME
, you can use the following command:
# 追加环境变量
echo "export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home" >> ~/.bash_profile
# 使环境变量立即生效
source ~/.bash_profile
After the addition is complete, you can use tail ~/.bash_profile
the command to confirm whether the addition is successful:
Verify that the installation was successful
Finally, enter the terminal and use it java -version
. If you can check the jdk version, the installation is successful: