Installing Android Studio requires the JDK, which is available on most Macs but is either too old or does not have a JDK.
1. Download the JDK
Download Java Development Kit from oracle’s official website, but it is a bit slow. If you don’t want to wait, you can click it.
2. View the JDK installation directory
Enter the following command on the terminal to view the JDK address
$ /usr/libexec/java_home -V
Copy the code
/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
Copy the code
JDK directory structure | The file function |
---|---|
bin | Executable files for JDK development tools. |
lib | Archive files used by development tools. |
jre | The root directory of the Java runtime environment, which contains the Java virtual machine, the runtime class package, and the Java application launcher, but does not contain development tools in the development environment. |
demo | Sample program with source code. |
include | Contains C language header files that support Java native interface and Java virtual machine debugger interface native programming technology. |
3. Configure JDK environment variables
- If it had been built before
.bash_profile
Hide the configuration file and enter it directly on the terminal$ open -e .bash_profile
Open the file. If not, enter the following command.
$ touch .bash_profile
Copy the code
- Then type the command below to open the file.
$ open -e .bash_profile
Copy the code
- Open the. Bash_profile file, enter the environment configuration parameters, put the following parameters in the file, and save (if the file is opened using vi, press Esc and enter :wq to exit. If the file is opened using text, enter command + S). Notice the
JAVA_HOME
This is the JDK installation path mentioned above, put your JDK installation path here, put it here, and save.
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH
Copy the code
$ source .bash_profile
Copy the code
- Enter the following command to check the path of the environment variable and check whether the configuration is successful.
$ echo $JAVA_HOME
Copy the code
$ java -version
Copy the code