-Host OS: Windows10 Home · Virtual OS: WSL Ubuntu18.04 lts (Ubuntu 18.04 is installed using wsl installed in windows 10)
-Install Java on ubuntu 18.04.
① Package update
$ sudo apt update
② Install OPEN JRE
$ sudo apt-get install default-jre
Check if JRE is installed with the following command
$ java --version
openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)
② Install OPEN JDK
$ sudo apt-get install default-jdk
Make sure you have the same installation as before. javac is a command that deals with the Java compiler.
$ javac --version
javac 11.0.6
Both ① and ② can be installed by specifying the version, but I think it is safe to install the latest version with default-jre and default-jdk until you are used to it.
③ Setting environment variables
First, check the java installation path with the following command.
$ sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Nothing to configure
I was able to confirm that the Java installation path is / usr / lib / jvm / java-11-openjdk-amd64.
Then open the bash file with the following command.
$ vi ~/.bashrc
Set the following environment variables in the bash file.
export JDK_HOME = "/usr/lib/jvm/java-11-openjdk-amd64"
export PATH="$JDK_HOME:$PATH"
After saving your edits with the: wq! Command, close the bash file.
** * When I read the article about Java environment construction, I often set the environment variable to $ JAVA_HOME, but then the VScode extension did not work and I felt it was inconvenient. ** **
Make sure the environment variables are set.
$ echo $JDK_HOME
/usr/lib/jvm/java-1.11.0-openjdk-amd64
You have successfully installed Java.
Recommended Posts