Home  >  Article  >  How to configure java environment variables?

How to configure java environment variables?

小老鼠
小老鼠Original
2023-12-22 14:17:541353browse

Steps to configure Java environment variables on Windows: 1. Download and install Java; 2. Find the Java installation directory; 3. Set the JAVA_HOME environment variable; 4. Modify the PATH environment variable; 5. Verify the configuration. Steps to configure Java environment variables on Unix/Linux: 1. Download and install Java; 2. Find the Java installation directory; 3. Set the JAVA_HOME environment variable; 4. Verify the configuration.

How to configure java environment variables?

Operating system for this tutorial: Windows 10 system, Dell G3 computer.

When configuring Java environment variables, you need to set two main environment variables: JAVA_HOME and PATH. The following are the steps to configure Java environment variables on Windows and Unix/Linux systems:

Configure Java environment variables on Windows:

1. Download and install Java:

First, download and install the Java Development Kit (JDK) from the official website (https://www.oracle.com/java/technologies/javase-downloads.html) or other reliable channels.

2. Find the Java installation directory:

Remember the directory path where you installed Java, usually similar to C:\Program Files\Java\jdk1.x.x.

3. Set the JAVA_HOME environment variable:

  • Right-click the computer (or this computer) and select "Properties".

  • Click "Advanced System Settings".

  • Under the "Advanced" tab, click the "Environment Variables" button.

  • In the "System Variables" section, click "New".

  • Variable name: JAVA_HOME, variable value: path to the Java installation directory (for example: C:\Program Files\Java\jdk1.x.x).

  • Click "OK" to close the window.

4. Modify the PATH environment variable:

  • In the "System Variables" section, find and select the "Path" variable, and click "Edit" .

  • Add ; at the end of the variable value, and then add %JAVA_HOME%\bin.

  • Click "OK" to save the changes.

5. Verify the configuration:

Open the command prompt (Command Prompt) and enter the following commands: java -version and javac -version. Make sure the correct Java version information is displayed.

Configure Java environment variables on Unix/Linux:

1. Download and install Java:

Use the package manager or download and install the Java Development Kit from the official website ( JDK).

2. Find the Java installation directory:

Remember the directory path where you installed Java, usually similar to /usr/lib/jvm/jdk1.x.x.

3. Set the JAVA_HOME environment variable:

Open the terminal window.

Edit the ~/.bashrc or ~/.bash_profile file and add the following line:

export JAVA_HOME=/usr/lib/jvm/jdk1.x.x
export PATH=$PATH:$JAVA_HOME/bin

Run source ~/.bashrc or source ~/.bash_profile to apply the changes.

4. Verify configuration:

Enter the following commands in the terminal: java -version and javac -version. Make sure the correct Java version information is displayed.

After this configuration, your system will be able to correctly identify and use Java.

The above is the detailed content of How to configure java environment variables?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn