To set the JAVA_HOME
environment variable from the Ubuntu shell on WSL2, you can follow these steps:
- Determine the path to the Java installation directory by running the following command:
sudo update-alternatives --config java
This will list all available Java installations, along with their corresponding directories. Choose the desired installation by typing the number next to it, then press Enter
.
- Export the
JAVA_HOME
environment variable by adding the following line to your~/.bashrc
file:
export JAVA_HOME=path/to/java/installation
Replace path/to/java/installation
with the path to the Java installation directory that you determined in step 1.
- Reload the
bashrc
file by running the following command:
source ~/.bashrc
- Test that the
JAVA_HOME
variable has been set correctly by running the following command:
echo $JAVA_HOME
This should output the path to the Java installation directory.
Note that these steps will only set the JAVA_HOME
variable for the current user. To set it system-wide, you will need to add the export
line to the /etc/environment
file instead of the bashrc
file.